diff --git a/Million Prototype/Form1.cs b/Million Prototype/Form1.cs index f3a08b7..5d7de81 100644 --- a/Million Prototype/Form1.cs +++ b/Million Prototype/Form1.cs @@ -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(); - + + //구매 데이터 + var buyList = new List(); + 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>(); + 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 + } + + } } diff --git a/Million/Manager/IndicatorSetupManager.cs b/Million/Manager/IndicatorSetupManager.cs index ac28456..06dcc15 100644 --- a/Million/Manager/IndicatorSetupManager.cs +++ b/Million/Manager/IndicatorSetupManager.cs @@ -90,8 +90,8 @@ namespace Million.Manager /// public static Dictionary> CalculateIndicator(Dictionary> dic, List 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> CalculateIndicator(Dictionary> dataList, List totalIndicatorList, object p1, object p2) - { - throw new NotImplementedException(); - } - } - + } } diff --git a/Million/Manager/RealtimeDataSettingManager.cs b/Million/Manager/RealtimeDataSettingManager.cs index b5ca6d9..8042f52 100644 --- a/Million/Manager/RealtimeDataSettingManager.cs +++ b/Million/Manager/RealtimeDataSettingManager.cs @@ -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")); } /// @@ -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); + } + } + /// /// Timer Event diff --git a/Million/Manager/ResultLogicManager.cs b/Million/Manager/ResultLogicManager.cs index 7b0dd9c..d80940d 100644 --- a/Million/Manager/ResultLogicManager.cs +++ b/Million/Manager/ResultLogicManager.cs @@ -21,7 +21,7 @@ namespace Million.Manager /// /// /// - private static Dictionary GetIndicateValue(Dictionary indicateDic, List totalIndicator, CandleData item) + public static Dictionary GetIndicateValue(Dictionary indicateDic, List totalIndicator, CandleData item) { var valDic = new Dictionary();