From 8cab39f94462f2f2764831696e06d15ff4a9de06 Mon Sep 17 00:00:00 2001 From: kyh <1329522@naver.com> Date: Fri, 7 Oct 2022 13:46:40 +0900 Subject: [PATCH] =?UTF-8?q?Log=20=20=EC=B2=98=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Million Buyer/MainForm.cs | 57 +++++++++++++++---- Million/Manager/RealtimeDataSettingManager.cs | 35 ++++++------ 2 files changed, 64 insertions(+), 28 deletions(-) diff --git a/Million Buyer/MainForm.cs b/Million Buyer/MainForm.cs index e95dccf..5ff6e32 100644 --- a/Million Buyer/MainForm.cs +++ b/Million Buyer/MainForm.cs @@ -141,7 +141,7 @@ namespace Million_Buyer ThreadFlag = true; bt_Start.Enabled = false; rd_buyer.Enabled = false; - rd_Realtime.Enabled = false; + rd_Realtime.Enabled = false; } } } @@ -171,6 +171,9 @@ namespace Million_Buyer /// private void ThreadFunction() { + //시간 체크 + var sw = new System.Diagnostics.Stopwatch(); + var dataList = new Dictionary>(); var sellIndicator = _saveResultData.SellSetupList.OfType().ToList(); @@ -207,9 +210,10 @@ namespace Million_Buyer RealtimeDataSettingManager realTimeMsg = null; - var standardTime = DateTime.Now; + var standardTime = DateTime.Now; - this.Invoke(new Action(delegate () + + this.BeginInvoke(new Action(delegate () { lb_StartDate.Text = standardTime.ToString("yyyy-MM-dd HH:mm:ss"); })); @@ -219,6 +223,9 @@ namespace Million_Buyer else InsertLog("Buyer 구동 중.."); + var cnt = 0; + sw.Start(); + while (ThreadFlag) { try @@ -251,13 +258,18 @@ namespace Million_Buyer firstFlag = 1; InsertLog("Deafult Data Setting 완료.."); + sw.Stop(); + InsertLog("Default 계산 시간 : " + sw.Elapsed.ToString()); } else { if (firstFlag == 1) { + sw.Restart(); dataList = realTimeMsg.ProcessRecentlyCandleDatas(dataList, candleTypeList); - + sw.Stop(); + if(sw.Elapsed.TotalSeconds > 1) + InsertLog("Ticker 계산 시간 : " + sw.Elapsed.ToString()); } } #endregion @@ -283,7 +295,7 @@ namespace Million_Buyer var dic = new Dictionary>(); var distinctIndicator = IndicatorSetupManager.Distinct(totalIndicatorList); - + sw.Restart(); foreach (var key in dataList.Keys) { var candleDataList = dataList[key].FirstOrDefault(t => t.ConGoodsData.CodeFullName == item); @@ -295,11 +307,18 @@ namespace Million_Buyer setup.excute(dic[key], true); } } + sw.Stop(); + if (sw.Elapsed.TotalSeconds > 1) + InsertLog("Execute 계산 시간 : " + sw.Elapsed.ToString()); var minDateTime = dic[MCandleTimeType.M1].Select(t => t.DateTime).Min(); var maxDateTime = dic[MCandleTimeType.M1].Select(t => t.DateTime).Max().AddHours(1); + sw.Restart(); dic = IndicatorSetupManager.CalculateIndicator(dic, totalIndicatorList, minDateTime, maxDateTime, cb_UpperMainIndi.Checked, item, true); + sw.Stop(); + if (sw.Elapsed.TotalSeconds > 1) + InsertLog("Indicator Calculate 계산 시간 : " + sw.Elapsed.ToString()); #endregion #region 사고 파는 로직 @@ -323,6 +342,7 @@ namespace Million_Buyer { if (overlapBuyManagementList[item]) { + sw.Restart(); //if (resultDataList.Select(t => t.MarketData).ToList().Any(t => t.CodeFullName == item)) continue; var time = DateTime.Now; var buyData = new CandleDataList(); @@ -340,13 +360,16 @@ namespace Million_Buyer overlapBuyManagementList[item] = false; InsertLog(buyData.ConGoodsData.CodeFullName + " Market Data 구입 DateTime : " + time.ToString("yyyy-MM-dd HH:mm:ss")); //grid 처리 구매항목, 구매 가격, 구매 개수, 구매시점 - this.Invoke(new Action(delegate () + this.BeginInvoke(new Action(delegate () { tl_BuyList.AppendNode(new object[] {buyData.ConGoodsData.CodeFullName, recentlyData.BuyValue, recentlyData.BuyCount, time.ToString("yyyy-MM-dd HH:mm:ss") }, null); lb_BuyMarketCount.Text = buyList.Count.ToString(); })); + sw.Stop(); + if (sw.Elapsed.TotalSeconds > 1) + InsertLog("Buy 계산 로직 : " + sw.Elapsed.ToString()); } } else @@ -359,6 +382,7 @@ namespace Million_Buyer var flag = sellScript.DicExcuteScript(recentlyData.CalculateFlag); if (flag) { + sw.Restart(); var buyItem = buyList.FirstOrDefault(x => x.ConGoodsData.CodeFullName == item); var time = DateTime.Now; @@ -397,10 +421,10 @@ namespace Million_Buyer //처리한 buyList는 삭제 buyList.Remove(buyItem); InsertLog(buyItem.ConGoodsData.CodeFullName + " Market Data 판매 DateTime : " + time.ToString("yyyy-MM-dd HH:mm:ss")); - this.Invoke(new Action(delegate () + this.BeginInvoke(new Action(delegate () { - //Grid 처리 - TreeListNode buyNode = null; + //Grid 처리 + TreeListNode buyNode = null; foreach (TreeListNode node in tl_BuyList.Nodes) { @@ -435,8 +459,8 @@ namespace Million_Buyer totalRate += resultData.FirstEarningRate; if (!RealTimeFlag) { - // 총 돈량 측정 - totalMoneyValue += (resultData.SellValue * (1 - 0.0005) - resultData.BuyValueList[0] * (1 - 0.0005)) * resultData.BuyCount; + // 총 돈량 측정 + totalMoneyValue += (resultData.SellValue * (1 - 0.0005) - resultData.BuyValueList[0] * (1 - 0.0005)) * resultData.BuyCount; } } @@ -445,9 +469,17 @@ namespace Million_Buyer if (!RealTimeFlag) lb_TotalMoneyValue.Text = totalMoneyValue + "원"; })); + if (sw.Elapsed.TotalSeconds > 1) + InsertLog("Sell 계산 로직 : " + sw.Elapsed.ToString()); } } #endregion + } + cnt++; + if(cnt%60 == 0) + { + InsertLog("Scanning......" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); + cnt = 0; } } catch (Exception e) @@ -566,7 +598,8 @@ namespace Million_Buyer /// private void InsertLog(string log) { - this.Invoke(new Action(delegate () + + this.BeginInvoke(new Action(delegate () { if (lb_log.Items.Count > 500) { diff --git a/Million/Manager/RealtimeDataSettingManager.cs b/Million/Manager/RealtimeDataSettingManager.cs index aa47530..302b64b 100644 --- a/Million/Manager/RealtimeDataSettingManager.cs +++ b/Million/Manager/RealtimeDataSettingManager.cs @@ -6,6 +6,7 @@ using System; using System.Collections.Generic; using System.Linq; using System.Threading; +using System.Threading.Tasks; using static Million.CommonProperty; namespace Million.Manager @@ -102,16 +103,12 @@ namespace Million.Manager this.timer.Dispose(); this.timer = null; - } - lock (obj) - { - this.tickerList = new List(); - } + } this.tc = new TimerCallback(TimerEvent); // 이벤트 발생 처리 루틴 //0.5초 마다 쌓는거 진행 -> DB데이터 가지고와서 부터 데이터 처리 - this.timer = new System.Threading.Timer(tc, null, 0, 500); + this.timer = new System.Threading.Timer(tc, null, 0, 1000); flag = true; } @@ -159,9 +156,10 @@ namespace Million.Manager foreach (var type in types) { var candleList = candleDatas[type]; - - foreach (var item in candleList) - { + Parallel.ForEach(candleList, item => + { + //foreach (var item in candleList) + //{ if(item.CandleDataLists_Im.Count > 0) basicDateTime = item.CandleDataLists_Im.Select(t => t.DateTime).Max(); @@ -176,7 +174,7 @@ namespace Million.Manager var callH = basicDateTime.Hour; var callM = basicDateTime.Minute; var callS = basicDateTime.Second; - + try { if (type == MCandleTimeType.M1) { var equalMinuteList = tickList.Where(t => t.DateTime.Minute == callM).ToList(); @@ -328,7 +326,12 @@ namespace Million.Manager item.CandleDataLists_Im.Add(candle); } } - } + }catch(Exception e) + { + throw; + } + //} + }); } return candleDatas; } @@ -352,15 +355,15 @@ namespace Million.Manager lock (obj) { var temp = GetRecentlyCandleData(); - - if(temp != null) { - tickerList.AddRange(temp); + + if (temp != null) + { + tickerList.AddRange(temp); //TODO 임시 var str = string.Format(@"INSERT INTO [ResultData].[dbo].[VerifyTickerData] VALUES ('{0}', @tickers);", temp[0].DateTime.ToString("yyyy-MM-dd HH:mm:ss:fff")); - Million.DbManagement.DBConnection.QueryInsertExcuter_VerifyTickerData - (str, temp); + Million.DbManagement.DBConnection.QueryInsertExcuter_VerifyTickerData(str, temp); } }