Buy, Sell 관련 Result Class 생성 완료

1. debug 확인 필요 -> 스펙 딸려서 112개 Codelist Test하는데 35초 정도 걸림
This commit is contained in:
kyh
2022-09-08 06:25:10 +09:00
parent 51cfe508cb
commit 1c12841e7f
4 changed files with 120 additions and 26 deletions

View File

@@ -162,10 +162,18 @@ namespace Million_Prototype
//사고 파는 rex 데이터 가져오는 부분
var buyRex = savedResultData.BuyRegularExpression;
var sellRex = savedResultData.SellRegularExpression;
var buyScript = new InteratorScripter();
buyScript.regularExpressionString = buyRex;
var sellScript = new InteratorScripter();
sellScript.regularExpressionString = sellRex;
//결과 데이터
var resultDataList = new List<SearchResult>();
//구매 데이터
var buyList = new List<CandleDataList>();
for (; ; )
{
if (firstFlag == 0)
@@ -182,19 +190,94 @@ namespace Million_Prototype
}
}
//Indicator 계산
dataList =IndicatorSetupManager.CalculateIndicator(dataList, totalIndicatorList, null, null);
//사고 파는 로직
if (DateTime.Now.Second == 0)
{
realTimeMsg.EndRealTimeTicker();
realTimeMsg.StartGetRealTimeTicker(null);
realTimeMsg.ClearTicker();
}
//Indicator 계산 -> Code full name 으로 for문 돌면서 계산 처리
foreach (var item in realTimeMsg.codeFullNameList)
{
var dic = new Dictionary<MCandleTimeType, List<CandleData>>();
foreach(var key in dataList.Keys)
{
var candleDataList = dataList[key].FirstOrDefault(t => t.ConGoodsData.CodeFullName == item);
dic[key] = candleDataList.CandleDataLists_Im;
}
var minDateTime = dic[MCandleTimeType.M1].Select(t => t.DateTime).Min();
var maxDateTime = dic[MCandleTimeType.M1].Select(t => t.DateTime).Max();
IndicatorSetupManager.CalculateIndicator(dic, totalIndicatorList, minDateTime,
maxDateTime);
#region 사고 파는 로직
//최신 데이터 가져오기
var recentlyData = dic[MCandleTimeType.M1].FirstOrDefault(t=>t.DateTime == maxDateTime);
if (recentlyData == null)
continue;
/*
* 로직 설명
* 1. Buy List에 있는지 확인
* 2. 없을 경우 추가(Buy Script 처리)
* 3. Buy List에 있을 경우 Sell Script 확인
* 4. Sell 처리 후 결과 처리
*/
//없을 시 -> BUY
if (!buyList.Any(t=>t.ConGoodsData.CodeFullName == item))
{
var flag = buyScript.DicExcuteScript(recentlyData.CalculateFlag);
if (flag)
{
var buyData = new CandleDataList();
buyData.CandleDataLists_Im.Add(recentlyData);
var valDic =ResultLogicManager.GetIndicateValue(recentlyData.CalculateFlag, totalIndicatorList, recentlyData);
recentlyData.BuyValue = OrderbookManager.GetAskPrice(CalculateManager.GetConditionValue(buyRex, valDic, recentlyData.CalculateFlag));
buyData.ConGoodsData = dataList[MCandleTimeType.M1].FirstOrDefault(t => t.ConGoodsData.CodeFullName == item).ConGoodsData;
buyList.Add(buyData);
}
}
else
{
var flag = sellScript.DicExcuteScript(recentlyData.CalculateFlag);
if (flag)
{
var buyItem = buyList.FirstOrDefault(t => t.ConGoodsData.CodeFullName == item);
var sellItem = recentlyData;
var valDic = ResultLogicManager.GetIndicateValue(sellItem.CalculateFlag, totalIndicatorList, sellItem);
sellItem.SellValue = OrderbookManager.GetAskPrice(CalculateManager.GetConditionValue(sellRex, valDic, sellItem.CalculateFlag));
var buyVal = buyItem.CandleDataLists_Im[0].BuyValue;
var sellVal = sellItem.SellValue;
var result = new SearchResult();
var rate = ((sellVal - buyVal) / buyVal) * 100;
result.FirstEarningRate = rate;
result.EndDate = sellItem.DateTime;
result.CodeFullName = buyItem.ConGoodsData.CodeFullName;
result.MarketData = buyItem.ConGoodsData;
result.BuyEarningRate.Add(rate);
result.BuyValueList.Add(buyVal);
result.BuyList.ConGoodsData = buyItem.ConGoodsData;
result.BuyList.CandleDataLists_Im.Add(buyItem.CandleDataLists_Im[0]);
result.StartDate = buyItem.CandleDataLists_Im[0].DateTime;
result.SellData = sellItem;
result.SellValue = sellVal;
result.TotalEarningRate = rate;
result.WinCount = rate > 0 ? 1 : 0;
result.LoseCount = rate < 0 ? 1 : 0;
result.FirstWinFlag = rate > 0 ? true : false;
resultDataList.Add(result);
//처리한 buyList는 삭제
buyList.Remove(buyItem);
}
}
#endregion
}
}
}

View File

@@ -90,8 +90,8 @@ namespace Million.Manager
/// <returns></returns>
public static Dictionary<MCandleTimeType, List<CandleData>> CalculateIndicator(Dictionary<MCandleTimeType, List<CandleData>> dic, List<IndicatorCoditionSetup> totalIndicators, DateTime startDate, DateTime endDate)
{
if (startDate == null) startDate = dic[MCandleTimeType.M1].Min(t => t.DateTime);
if (endDate == null) endDate = dic[MCandleTimeType.M1].Max(t => t.DateTime);
if (startDate == null) startDate = dic[MCandleTimeType.M1].Select(t => t.DateTime).Min();
if (endDate == null) endDate = dic[MCandleTimeType.M1].Select(t => t.DateTime).Max();
dic[MCandleTimeType.M1] = dic[MCandleTimeType.M1].Where(t => startDate <= t.DateTime && t.DateTime < endDate).ToList();
// Sub Indicator string list 반환
@@ -117,11 +117,5 @@ namespace Million.Manager
return dic;
}
public static Dictionary<MCandleTimeType, List<CandleDataList>> CalculateIndicator(Dictionary<MCandleTimeType, List<CandleDataList>> dataList, List<IndicatorCoditionSetup> totalIndicatorList, object p1, object p2)
{
throw new NotImplementedException();
}
}
}
}

View File

@@ -49,6 +49,14 @@ namespace Million.Manager
{
this.codeFullNameList = codeFullNameList;
}
//TODO Market ignore 처리 필요 -> 임시로 비트토랜트만 삭제
this.codeFullNameList.Remove("KRW-BTT");
if(CommonProperty.selectedMarketOfPlaceList !=null)
CommonProperty.selectedMarketOfPlaceList.Remove(selectedMarketOfPlaceList.FirstOrDefault(t => t.CodeFullName == "KRW-BTT"));
if (CommonProperty.recentlyMarketOfPlaceList != null)
CommonProperty.recentlyMarketOfPlaceList.Remove(recentlyMarketOfPlaceList.FirstOrDefault(t => t.CodeFullName == "KRW-BTT"));
}
/// <summary>
@@ -222,10 +230,10 @@ namespace Million.Manager
if (list.Count > 0)
{
// 데이터 가져올떄 1분 이상 걸릴 시 처리할 데이터
var minList = list.Select(t => t.DateTime.Minute).ToList();
var minList = list.Select(t => t.DateTime.Minute).Distinct().ToList();
minList.Sort();
foreach(var min in minList)
foreach (var min in minList)
{
var equalList = list.Where(t => t.DateTime.Minute == min).OrderBy(t=>t.DateTime).ToList();
@@ -291,7 +299,7 @@ namespace Million.Manager
date.AddSeconds(-1 * callS);
candle.DateTime = date;
if (item.CandleDataLists_Im.Count > 300)
item.CandleDataLists_Im.RemoveRange(0, item.CandleDataLists_Im.Count - 300);
item.CandleDataLists_Im.RemoveRange(0, 100);
item.CandleDataLists_Im.Add(candle);
}
}
@@ -315,7 +323,7 @@ namespace Million.Manager
candle.DateTime = date;
if (item.CandleDataLists_Im.Count > 300)
item.CandleDataLists_Im.RemoveRange(0, item.CandleDataLists_Im.Count - 300);
item.CandleDataLists_Im.RemoveRange(0, 100);
item.CandleDataLists_Im.Add(candle);
}
}
@@ -324,6 +332,15 @@ namespace Million.Manager
return candleDatas;
}
public void ClearTicker()
{
lock (obj)
{
if (tickerList.Count > 3600)
tickerList.RemoveRange(0, 1200);
}
}
/// <summary>
/// Timer Event

View File

@@ -21,7 +21,7 @@ namespace Million.Manager
/// <param name="totalIndicator"></param>
/// <param name="item"></param>
/// <returns></returns>
private static Dictionary<string, double> GetIndicateValue(Dictionary<string, bool> indicateDic, List<IndicatorCoditionSetup> totalIndicator, CandleData item)
public static Dictionary<string, double> GetIndicateValue(Dictionary<string, bool> indicateDic, List<IndicatorCoditionSetup> totalIndicator, CandleData item)
{
var valDic = new Dictionary<string, double>();