122 lines
4.9 KiB
C#
122 lines
4.9 KiB
C#
using Million.Data;
|
|
using Million.IndicatorConditionSetup;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using static Million.CommonProperty;
|
|
|
|
namespace Million.Manager
|
|
{
|
|
public static class IndicatorSetupManager
|
|
{
|
|
|
|
public static List<IndicatorCoditionSetup> InitDataSetup(List<object> setupList)
|
|
{
|
|
var indicatorList = new List<IndicatorCoditionSetup>();
|
|
|
|
foreach (var setup in setupList)
|
|
{
|
|
//Ichmok
|
|
if (setup.GetType() == typeof(IchimokuConditionSetup))
|
|
{
|
|
indicatorList.Add((IchimokuConditionSetup)setup);
|
|
}
|
|
//bol
|
|
else if (setup.GetType() == typeof(BolingerConditionSetup))
|
|
{
|
|
indicatorList.Add((BolingerConditionSetup)setup);
|
|
}
|
|
else if (setup.GetType() == typeof(MovingAverageConditionSetup))
|
|
{
|
|
indicatorList.Add((MovingAverageConditionSetup)setup);
|
|
}
|
|
else if (setup.GetType() == typeof(PriceRateCondtionSetup))
|
|
{
|
|
indicatorList.Add((PriceRateCondtionSetup)setup);
|
|
}else if(setup.GetType() == typeof(CompareConditionSetup))
|
|
{
|
|
indicatorList.Add((CompareConditionSetup)setup);
|
|
}
|
|
}
|
|
|
|
return indicatorList;
|
|
}
|
|
|
|
public static List<IndicatorCoditionSetup> Distinct(List<IndicatorCoditionSetup> list)
|
|
{
|
|
var indicatorList = new List<IndicatorCoditionSetup>();
|
|
|
|
foreach (var setup in list)
|
|
{
|
|
var data = indicatorList.Find(x => x.Equals((IndicatorCoditionSetup)setup));
|
|
if (data == null) indicatorList.Add((IndicatorCoditionSetup)setup);
|
|
}
|
|
|
|
return indicatorList;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Market 별 Start, End Date를 기준으로 불러온 데이터를 Indicator 계산 후 Return 해주는 함수
|
|
/// </summary>
|
|
/// <param name="totalIndicators"></param>
|
|
/// <param name="startDate"></param>
|
|
/// <param name="endDate"></param>
|
|
/// <param name="market"></param>
|
|
/// <returns></returns>
|
|
public static Dictionary<MCandleTimeType, List<CandleData>> GetCalculateCandleData(List<IndicatorCoditionSetup> totalIndicators, DateTime startDate,
|
|
DateTime endDate, MarketData market = null)
|
|
{
|
|
if (market == null)
|
|
{
|
|
var tableList = selectedMarketOfPlaceList;
|
|
market = tableList.FirstOrDefault(t => t.CoinFullName == "KRW-BTC");
|
|
}
|
|
|
|
|
|
var distinctIndicator = Distinct(totalIndicators);
|
|
|
|
// 총 데이터
|
|
var dic = DataManager.GetStandardData(totalIndicators, startDate, endDate, market, distinctIndicator, true);
|
|
|
|
return CalculateIndicator(dic, totalIndicators, startDate, endDate, null, false);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 계산만 처리(Start Date, End Date가 Null일 경우 M1의 최소, 최대값으로 처리)
|
|
/// </summary>
|
|
/// <param name="dic"></param>
|
|
/// <param name="totalIndicators"></param>
|
|
/// <param name="startDate"></param>
|
|
/// <param name="endDate"></param>
|
|
/// <returns></returns>
|
|
public static Dictionary<MCandleTimeType, List<CandleData>> CalculateIndicator(Dictionary<MCandleTimeType, List<CandleData>> dic,
|
|
List<IndicatorCoditionSetup> totalIndicators, DateTime startDate, DateTime endDate,string coinFullName = null, bool recentlyDataFlag = false, CandleData buyData = null)
|
|
{
|
|
|
|
dic[MCandleTimeType.M1] = dic[MCandleTimeType.M1].Where(t => startDate <= t.DateTime && t.DateTime < endDate).ToList();
|
|
// Sub Indicator string list 반환
|
|
var subIndStringList = DataManager.GetSubIndicatorStringList(totalIndicators);
|
|
|
|
// Sub Indicator Class
|
|
var subIndicator = totalIndicators.Where(t => subIndStringList.Any(u => u == t.IndexString)).ToList();
|
|
|
|
// 선처리
|
|
CalculateManager.GetCalculateIndicator(totalIndicators, subIndStringList, null, startDate,
|
|
endDate, dic[MCandleTimeType.M1], subIndicator, dic, recentlyDataFlag, coinFullName, buyData);
|
|
|
|
var totalIndi = totalIndicators.Select(t => t.IndexString).ToList();
|
|
|
|
// 중복계산 방지
|
|
foreach (var item in subIndStringList)
|
|
totalIndi.Remove(item);
|
|
|
|
// 후처리
|
|
CalculateManager.GetCalculateIndicator(totalIndicators, totalIndi, null, startDate,
|
|
endDate, dic[MCandleTimeType.M1], subIndicator, dic, recentlyDataFlag, coinFullName, buyData);
|
|
return dic;
|
|
}
|
|
}
|
|
}
|