diff --git a/Million Buyer/MainForm.Designer.cs b/Million Buyer/MainForm.Designer.cs index dede33a..943a908 100644 --- a/Million Buyer/MainForm.Designer.cs +++ b/Million Buyer/MainForm.Designer.cs @@ -29,6 +29,7 @@ private void InitializeComponent() { this.groupBox1 = new System.Windows.Forms.GroupBox(); + this.lb_IndiName = new System.Windows.Forms.Label(); this.bt_Modify = new System.Windows.Forms.Button(); this.label6 = new System.Windows.Forms.Label(); this.tb_CycleMoneyValue = new System.Windows.Forms.TextBox(); @@ -46,15 +47,30 @@ this.label4 = new System.Windows.Forms.Label(); this.bt_Start = new System.Windows.Forms.Button(); this.bt_Stop = new System.Windows.Forms.Button(); - this.lb_IndiName = new System.Windows.Forms.Label(); this.rd_Realtime = new System.Windows.Forms.RadioButton(); this.rd_buyer = new System.Windows.Forms.RadioButton(); - this.treeList1 = new DevExpress.XtraTreeList.TreeList(); - this.treeList2 = new DevExpress.XtraTreeList.TreeList(); + this.tl_BuyList = new DevExpress.XtraTreeList.TreeList(); + this.tl_Result = new DevExpress.XtraTreeList.TreeList(); + this.button1 = new System.Windows.Forms.Button(); + this.label8 = new System.Windows.Forms.Label(); + this.label9 = new System.Windows.Forms.Label(); + this.BuyMarket = new DevExpress.XtraTreeList.Columns.TreeListColumn(); + this.BuyValue = new DevExpress.XtraTreeList.Columns.TreeListColumn(); + this.BuyCount = new DevExpress.XtraTreeList.Columns.TreeListColumn(); + this.BuyDateTime = new DevExpress.XtraTreeList.Columns.TreeListColumn(); + this.Market = new DevExpress.XtraTreeList.Columns.TreeListColumn(); + this.BuyValueData = new DevExpress.XtraTreeList.Columns.TreeListColumn(); + this.BuyCountData = new DevExpress.XtraTreeList.Columns.TreeListColumn(); + this.BuyDateTimeData = new DevExpress.XtraTreeList.Columns.TreeListColumn(); + this.SellValueData = new DevExpress.XtraTreeList.Columns.TreeListColumn(); + this.SellCountData = new DevExpress.XtraTreeList.Columns.TreeListColumn(); + this.SellDateTimeData = new DevExpress.XtraTreeList.Columns.TreeListColumn(); + this.RateData = new DevExpress.XtraTreeList.Columns.TreeListColumn(); + this.MoneyData = new DevExpress.XtraTreeList.Columns.TreeListColumn(); this.groupBox1.SuspendLayout(); this.groupBox2.SuspendLayout(); - ((System.ComponentModel.ISupportInitialize)(this.treeList1)).BeginInit(); - ((System.ComponentModel.ISupportInitialize)(this.treeList2)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.tl_BuyList)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.tl_Result)).BeginInit(); this.SuspendLayout(); // // groupBox1 @@ -68,24 +84,33 @@ this.groupBox1.Controls.Add(this.label1); this.groupBox1.Location = new System.Drawing.Point(12, 52); this.groupBox1.Name = "groupBox1"; - this.groupBox1.Size = new System.Drawing.Size(362, 115); + this.groupBox1.Size = new System.Drawing.Size(362, 111); this.groupBox1.TabIndex = 5; this.groupBox1.TabStop = false; this.groupBox1.Text = "데이터 Setting"; // + // lb_IndiName + // + this.lb_IndiName.AutoSize = true; + this.lb_IndiName.Location = new System.Drawing.Point(142, 82); + this.lb_IndiName.Name = "lb_IndiName"; + this.lb_IndiName.Size = new System.Drawing.Size(0, 12); + this.lb_IndiName.TabIndex = 7; + // // bt_Modify // - this.bt_Modify.Location = new System.Drawing.Point(142, 83); + this.bt_Modify.Location = new System.Drawing.Point(288, 77); this.bt_Modify.Name = "bt_Modify"; this.bt_Modify.Size = new System.Drawing.Size(68, 23); this.bt_Modify.TabIndex = 6; this.bt_Modify.Text = "선택"; this.bt_Modify.UseVisualStyleBackColor = true; + this.bt_Modify.Click += new System.EventHandler(this.bt_Modify_Click); // // label6 // this.label6.AutoSize = true; - this.label6.Location = new System.Drawing.Point(95, 88); + this.label6.Location = new System.Drawing.Point(95, 82); this.label6.Name = "label6"; this.label6.Size = new System.Drawing.Size(41, 12); this.label6.TabIndex = 4; @@ -95,6 +120,7 @@ // this.tb_CycleMoneyValue.Location = new System.Drawing.Point(142, 50); this.tb_CycleMoneyValue.Name = "tb_CycleMoneyValue"; + this.tb_CycleMoneyValue.ReadOnly = true; this.tb_CycleMoneyValue.Size = new System.Drawing.Size(214, 21); this.tb_CycleMoneyValue.TabIndex = 3; // @@ -102,6 +128,7 @@ // this.tb_CycleCount.Location = new System.Drawing.Point(142, 20); this.tb_CycleCount.Name = "tb_CycleCount"; + this.tb_CycleCount.ReadOnly = true; this.tb_CycleCount.Size = new System.Drawing.Size(214, 21); this.tb_CycleCount.TabIndex = 2; // @@ -133,9 +160,9 @@ this.groupBox2.Controls.Add(this.label5); this.groupBox2.Controls.Add(this.label3); this.groupBox2.Controls.Add(this.label4); - this.groupBox2.Location = new System.Drawing.Point(12, 173); + this.groupBox2.Location = new System.Drawing.Point(12, 169); this.groupBox2.Name = "groupBox2"; - this.groupBox2.Size = new System.Drawing.Size(362, 557); + this.groupBox2.Size = new System.Drawing.Size(362, 561); this.groupBox2.TabIndex = 6; this.groupBox2.TabStop = false; this.groupBox2.Text = "데이터 현황"; @@ -210,29 +237,23 @@ // // bt_Start // - this.bt_Start.Location = new System.Drawing.Point(1375, 741); + this.bt_Start.Location = new System.Drawing.Point(1441, 737); this.bt_Start.Name = "bt_Start"; this.bt_Start.Size = new System.Drawing.Size(75, 23); this.bt_Start.TabIndex = 7; this.bt_Start.Text = "Start"; this.bt_Start.UseVisualStyleBackColor = true; + this.bt_Start.Click += new System.EventHandler(this.bt_Start_Click); // // bt_Stop // - this.bt_Stop.Location = new System.Drawing.Point(1456, 741); + this.bt_Stop.Location = new System.Drawing.Point(1522, 737); this.bt_Stop.Name = "bt_Stop"; this.bt_Stop.Size = new System.Drawing.Size(75, 23); this.bt_Stop.TabIndex = 8; this.bt_Stop.Text = "Stop"; this.bt_Stop.UseVisualStyleBackColor = true; - // - // lb_IndiName - // - this.lb_IndiName.AutoSize = true; - this.lb_IndiName.Location = new System.Drawing.Point(216, 88); - this.lb_IndiName.Name = "lb_IndiName"; - this.lb_IndiName.Size = new System.Drawing.Size(0, 12); - this.lb_IndiName.TabIndex = 7; + this.bt_Stop.Click += new System.EventHandler(this.bt_Stop_Click); // // rd_Realtime // @@ -258,27 +279,177 @@ this.rd_buyer.UseVisualStyleBackColor = true; this.rd_buyer.CheckedChanged += new System.EventHandler(this.rd_buyer_CheckedChanged); // - // treeList1 + // tl_BuyList // - this.treeList1.Location = new System.Drawing.Point(380, 31); - this.treeList1.Name = "treeList1"; - this.treeList1.Size = new System.Drawing.Size(576, 699); - this.treeList1.TabIndex = 11; + this.tl_BuyList.Columns.AddRange(new DevExpress.XtraTreeList.Columns.TreeListColumn[] { + this.BuyMarket, + this.BuyValue, + this.BuyCount, + this.BuyDateTime}); + this.tl_BuyList.Location = new System.Drawing.Point(380, 31); + this.tl_BuyList.Name = "tl_BuyList"; + this.tl_BuyList.Size = new System.Drawing.Size(415, 699); + this.tl_BuyList.TabIndex = 11; // - // treeList2 + // tl_Result // - this.treeList2.Location = new System.Drawing.Point(962, 31); - this.treeList2.Name = "treeList2"; - this.treeList2.Size = new System.Drawing.Size(567, 699); - this.treeList2.TabIndex = 12; + this.tl_Result.Columns.AddRange(new DevExpress.XtraTreeList.Columns.TreeListColumn[] { + this.Market, + this.BuyValueData, + this.BuyCountData, + this.BuyDateTimeData, + this.SellValueData, + this.SellCountData, + this.SellDateTimeData, + this.RateData, + this.MoneyData}); + this.tl_Result.Location = new System.Drawing.Point(801, 31); + this.tl_Result.Name = "tl_Result"; + this.tl_Result.Size = new System.Drawing.Size(796, 699); + this.tl_Result.TabIndex = 12; + // + // button1 + // + this.button1.Location = new System.Drawing.Point(17, 737); + this.button1.Name = "button1"; + this.button1.Size = new System.Drawing.Size(91, 23); + this.button1.TabIndex = 13; + this.button1.Text = "데이터 저장"; + this.button1.UseVisualStyleBackColor = true; + this.button1.Click += new System.EventHandler(this.button1_Click); + // + // label8 + // + this.label8.AutoSize = true; + this.label8.Location = new System.Drawing.Point(378, 9); + this.label8.Name = "label8"; + this.label8.Size = new System.Drawing.Size(57, 12); + this.label8.TabIndex = 14; + this.label8.Text = "구매 목록"; + // + // label9 + // + this.label9.AutoSize = true; + this.label9.Location = new System.Drawing.Point(799, 9); + this.label9.Name = "label9"; + this.label9.Size = new System.Drawing.Size(129, 12); + this.label9.TabIndex = 15; + this.label9.Text = "구매 및 판매 완료 목록"; + // + // BuyMarket + // + this.BuyMarket.Caption = "구매 항목"; + this.BuyMarket.FieldName = "BuyMarket"; + this.BuyMarket.Name = "BuyMarket"; + this.BuyMarket.Visible = true; + this.BuyMarket.VisibleIndex = 0; + // + // BuyValue + // + this.BuyValue.Caption = "구매 가격"; + this.BuyValue.FieldName = "BuyValue"; + this.BuyValue.Name = "BuyValue"; + this.BuyValue.Visible = true; + this.BuyValue.VisibleIndex = 1; + // + // BuyCount + // + this.BuyCount.Caption = "구매 개수"; + this.BuyCount.FieldName = "BuyCount"; + this.BuyCount.Name = "BuyCount"; + this.BuyCount.Visible = true; + this.BuyCount.VisibleIndex = 2; + // + // BuyDateTime + // + this.BuyDateTime.Caption = "검출 된 시간"; + this.BuyDateTime.FieldName = "BuyDateTime"; + this.BuyDateTime.Name = "BuyDateTime"; + this.BuyDateTime.Visible = true; + this.BuyDateTime.VisibleIndex = 3; + // + // Market + // + this.Market.Caption = "항목"; + this.Market.FieldName = "Market"; + this.Market.Name = "Market"; + this.Market.Visible = true; + this.Market.VisibleIndex = 0; + // + // BuyValueData + // + this.BuyValueData.Caption = "구매 가격"; + this.BuyValueData.FieldName = "BuyValueData"; + this.BuyValueData.Name = "BuyValueData"; + this.BuyValueData.Visible = true; + this.BuyValueData.VisibleIndex = 1; + // + // BuyCountData + // + this.BuyCountData.Caption = "구매 개수"; + this.BuyCountData.FieldName = "BuyCountData"; + this.BuyCountData.Name = "BuyCountData"; + this.BuyCountData.Visible = true; + this.BuyCountData.VisibleIndex = 2; + // + // BuyDateTimeData + // + this.BuyDateTimeData.Caption = "구매 시간"; + this.BuyDateTimeData.FieldName = "BuyDateTimeData"; + this.BuyDateTimeData.Name = "BuyDateTimeData"; + this.BuyDateTimeData.Visible = true; + this.BuyDateTimeData.VisibleIndex = 3; + // + // SellValueData + // + this.SellValueData.Caption = "판매 가격"; + this.SellValueData.FieldName = "SellValueData"; + this.SellValueData.Name = "SellValueData"; + this.SellValueData.Visible = true; + this.SellValueData.VisibleIndex = 4; + // + // SellCountData + // + this.SellCountData.Caption = "판매 개수"; + this.SellCountData.FieldName = "SellCountData"; + this.SellCountData.Name = "SellCountData"; + this.SellCountData.Visible = true; + this.SellCountData.VisibleIndex = 5; + // + // SellDateTimeData + // + this.SellDateTimeData.Caption = "판매 시간"; + this.SellDateTimeData.FieldName = "SellDateTimeData"; + this.SellDateTimeData.Name = "SellDateTimeData"; + this.SellDateTimeData.Visible = true; + this.SellDateTimeData.VisibleIndex = 6; + // + // RateData + // + this.RateData.Caption = "수익률"; + this.RateData.FieldName = "RateData"; + this.RateData.Name = "RateData"; + this.RateData.Visible = true; + this.RateData.VisibleIndex = 7; + // + // MoneyData + // + this.MoneyData.Caption = "수익금"; + this.MoneyData.FieldName = "MoneyData"; + this.MoneyData.Name = "MoneyData"; + this.MoneyData.Visible = true; + this.MoneyData.VisibleIndex = 8; // // MainForm // this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 12F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(1541, 771); - this.Controls.Add(this.treeList2); - this.Controls.Add(this.treeList1); + this.ClientSize = new System.Drawing.Size(1609, 771); + this.Controls.Add(this.label9); + this.Controls.Add(this.label8); + this.Controls.Add(this.button1); + this.Controls.Add(this.tl_Result); + this.Controls.Add(this.tl_BuyList); this.Controls.Add(this.rd_buyer); this.Controls.Add(this.rd_Realtime); this.Controls.Add(this.bt_Stop); @@ -291,8 +462,8 @@ this.groupBox1.PerformLayout(); this.groupBox2.ResumeLayout(false); this.groupBox2.PerformLayout(); - ((System.ComponentModel.ISupportInitialize)(this.treeList1)).EndInit(); - ((System.ComponentModel.ISupportInitialize)(this.treeList2)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.tl_BuyList)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.tl_Result)).EndInit(); this.ResumeLayout(false); this.PerformLayout(); @@ -321,8 +492,24 @@ private System.Windows.Forms.Label lb_IndiName; private System.Windows.Forms.RadioButton rd_Realtime; private System.Windows.Forms.RadioButton rd_buyer; - private DevExpress.XtraTreeList.TreeList treeList1; - private DevExpress.XtraTreeList.TreeList treeList2; + private DevExpress.XtraTreeList.TreeList tl_BuyList; + private DevExpress.XtraTreeList.TreeList tl_Result; + private System.Windows.Forms.Button button1; + private System.Windows.Forms.Label label8; + private System.Windows.Forms.Label label9; + private DevExpress.XtraTreeList.Columns.TreeListColumn BuyMarket; + private DevExpress.XtraTreeList.Columns.TreeListColumn BuyValue; + private DevExpress.XtraTreeList.Columns.TreeListColumn BuyCount; + private DevExpress.XtraTreeList.Columns.TreeListColumn BuyDateTime; + private DevExpress.XtraTreeList.Columns.TreeListColumn Market; + private DevExpress.XtraTreeList.Columns.TreeListColumn BuyValueData; + private DevExpress.XtraTreeList.Columns.TreeListColumn BuyCountData; + private DevExpress.XtraTreeList.Columns.TreeListColumn BuyDateTimeData; + private DevExpress.XtraTreeList.Columns.TreeListColumn SellValueData; + private DevExpress.XtraTreeList.Columns.TreeListColumn SellCountData; + private DevExpress.XtraTreeList.Columns.TreeListColumn SellDateTimeData; + private DevExpress.XtraTreeList.Columns.TreeListColumn RateData; + private DevExpress.XtraTreeList.Columns.TreeListColumn MoneyData; } } diff --git a/Million Buyer/MainForm.cs b/Million Buyer/MainForm.cs index 612c02c..b6b686a 100644 --- a/Million Buyer/MainForm.cs +++ b/Million Buyer/MainForm.cs @@ -1,5 +1,11 @@ -using Million; +using DevExpress.XtraTreeList.Nodes; +using Million; +using Million.Data; using Million.DbManagement; +using Million.IndicatorConditionSetup; +using Million.Manager; +using Million.SaveData; +using Million_Buyer.SubForm; using System; using System.Collections.Generic; using System.ComponentModel; @@ -7,15 +13,24 @@ using System.Data; using System.Drawing; using System.Linq; using System.Text; +using System.Threading; using System.Threading.Tasks; using System.Windows.Forms; +using static Million.CommonProperty; namespace Million_Buyer { public partial class MainForm : Form { - bool RealTimeMode = true; + public SavedResultData _saveResultData; + bool SetIndicator = false; + bool ThreadFlag = false; + + Thread thread = null; + + //결과 데이터 + List resultDataList = new List(); public MainForm() { @@ -36,7 +51,11 @@ namespace Million_Buyer Million.DbManagement.DBConnection.QueryUpdateExcuter (CommonProperty.DbConnectionResultData, DbServiceFunctions.CreateRealTimeIndicatorTableQuery()); - + _saveResultData = new SavedResultData + { + BuySetupList = new List(), + SellSetupList = new List() + }; } /// @@ -69,5 +88,399 @@ namespace Million_Buyer tb_CycleCount.ReadOnly = flag; tb_CycleMoneyValue.ReadOnly = flag; } + + /// + /// 조건식 폼 띄우기 + /// + /// + /// + private void bt_Modify_Click(object sender, EventArgs e) + { + var subForm = new IndicatorLoadForm(); + if(subForm.ShowDialog() == DialogResult.OK) + { + _saveResultData.SellSetupList = ((List)subForm.selectData["SellSetupList"]); + _saveResultData.BuySetupList = ((List)subForm.selectData["BuySetupList"]); + _saveResultData.BuyRegularExpression = subForm.selectData["BuyRegularExpression"].ToString(); + _saveResultData.SellRegularExpression = subForm.selectData["SellRegularExpression"].ToString(); + lb_IndiName.Text = subForm.selectData["Name"].ToString(); + SetIndicator = true; + } + } + /// + /// Start Button Event + /// + /// + /// + private void bt_Start_Click(object sender, EventArgs e) + { + if (!SetIndicator) + { + MessageBox.Show("Indicator Setting 필요"); + } + else + { + if (!ThreadFlag) + { + thread = new Thread(ThreadFunction); + thread.Start(); + ThreadFlag = true; + } + } + } + + /// + /// Stop Button Event + /// + /// + /// + private void bt_Stop_Click(object sender, EventArgs e) + { + ThreadFlag = false; + if (!RealTimeMode && thread != null) thread.Abort(); + + /* + * 종료 된 후 데이터 처리 소스는 여기서 처리 + * 1. Grid에 Stop 후 데이터 처리 + * 2. 종료 후 데이터 저장 처리 + */ + + } + + /// + /// 실제 동작 Thread + /// + private void ThreadFunction() + { + var dataList = new Dictionary>(); + + var sellIndicator = _saveResultData.SellSetupList.OfType().ToList(); + var buyIndicator = _saveResultData.BuySetupList.OfType().ToList(); + var totalIndicatorList = new List(); + + totalIndicatorList.AddRange(sellIndicator); + totalIndicatorList.AddRange(buyIndicator); + + var candleTypeList = totalIndicatorList.Select(t => t.MCandleTimeType).ToList(); + candleTypeList.Add(MCandleTimeType.M1); + candleTypeList = candleTypeList.Distinct().ToList(); + + //사고 파는 rex 데이터 가져오는 부분 + var buyRex = _saveResultData.BuyRegularExpression; + var sellRex = _saveResultData.SellRegularExpression; + + var buyScript = new InteratorScripter(); + buyScript.regularExpressionString = buyRex; + var sellScript = new InteratorScripter(); + sellScript.regularExpressionString = sellRex; + + //save 데이터 + _saveResultData.StartDateTime = DateTime.Now; + + //구매 데이터 + var buyList = new List(); + var saveFlag = true; + + //구매 후 데이터 여러개 계속 겹치는 경우 제외하기 위한 List + var overlapBuyManagementList = new Dictionary(); + + int firstFlag = 0; + + RealtimeDataSettingManager realTimeMsg = null; + + var standardTime = DateTime.Now; + + while (ThreadFlag) + { + # region 기본 데이터 Setting + if (firstFlag == 0) + { + realTimeMsg = new RealtimeDataSettingManager(null, PaymentType.KRW); + dataList = realTimeMsg.GetRealTimeCandleData(candleTypeList, 200); + foreach (var item in realTimeMsg.codeFullNameList) + { + overlapBuyManagementList[item] = true; + } + firstFlag = 1; + } + else + { + if (firstFlag == 1) + { + dataList = realTimeMsg.ProcessRecentlyCandleDatas(dataList, candleTypeList); + + } + } + #endregion + + //Ticker 초기화 + if (DateTime.Now.Minute == 0 && saveFlag) + { + realTimeMsg.ClearTicker(); + } + else if (DateTime.Now.Minute > 1) saveFlag = true; + + foreach (var item in realTimeMsg.codeFullNameList) + { + # region Indicator 계산 -> Code full name 으로 for문 돌면서 계산 처리 + + var dic = new Dictionary>(); + var distinctIndicator = IndicatorSetupManager.Distinct(totalIndicatorList); + + foreach (var key in dataList.Keys) + { + var candleDataList = dataList[key].FirstOrDefault(t => t.ConGoodsData.CodeFullName == item); + dic[key] = candleDataList.CandleDataLists_Im; + + var indicatorSetUpList = distinctIndicator.Where(t => t.MCandleTimeType == key).ToList(); + foreach (var setup in indicatorSetUpList) + { + setup.excute(dic[key], true); + } + } + + var minDateTime = dic[MCandleTimeType.M1].Select(t => t.DateTime).Min(); + var maxDateTime = dic[MCandleTimeType.M1].Select(t => t.DateTime).Max().AddHours(1); + + dic = IndicatorSetupManager.CalculateIndicator(dic, totalIndicatorList, minDateTime, maxDateTime, true); + #endregion + + #region 사고 파는 로직 + //최신 데이터 가져오기 + var recentlyData = dic[MCandleTimeType.M1][dic[MCandleTimeType.M1].Count - 1]; + 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) + { + if (overlapBuyManagementList[item]) + { + //if (resultDataList.Select(t => t.MarketData).ToList().Any(t => t.CodeFullName == item)) continue; + var time = DateTime.Now; + 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)); + recentlyData.BuyTime = time; + + // 임시 -> 실시간은 1개만 삿다고 처리 + recentlyData.BuyCount = 1; + + buyData.ConGoodsData = dataList[MCandleTimeType.M1].FirstOrDefault(t => t.ConGoodsData.CodeFullName == item).ConGoodsData; + buyList.Add(buyData); + overlapBuyManagementList[item] = false; + + //grid 처리 구매항목, 구매 가격, 구매 개수, 구매시점 + 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(); + } + } + else + { + overlapBuyManagementList[item] = true; + } + } + else + { + var flag = sellScript.DicExcuteScript(recentlyData.CalculateFlag); + if (flag) + { + var buyItem = buyList.FirstOrDefault(x => x.ConGoodsData.CodeFullName == item); + + var time = DateTime.Now; + var sellItem = recentlyData; + var valDic = ResultLogicManager.GetIndicateValue(sellItem.CalculateFlag, totalIndicatorList, sellItem); + sellItem.SellValue = OrderbookManager.GetAskPrice(CalculateManager.GetConditionValue(sellRex, valDic, sellItem.CalculateFlag)); + sellItem.SellTime = time; + + var buyCandleData = buyItem.CandleDataLists_Im[0]; + + var sellVal = sellItem.SellValue; + + var result = new SearchResult(); + var rate = ((sellVal - buyCandleData.BuyValue) / buyCandleData.BuyValue) * 100; + result.FirstEarningRate = rate; + result.EndDate = sellItem.DateTime; + result.CodeFullName = buyItem.ConGoodsData.CodeFullName; + result.MarketData = buyItem.ConGoodsData; + result.BuyEarningRate.Add(rate); + result.BuyValueList.Add(buyCandleData.BuyValue); + 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; + + //실시간 검증은 1개로 처리 + result.BuyCount = buyItem.CandleDataLists_Im[0].BuyCount; + result.SellCount = buyItem.CandleDataLists_Im[0].BuyCount; + + resultDataList.Add(result); + //처리한 buyList는 삭제 + buyList.Remove(buyItem); + + //Grid 처리 + var buyNode = new TreeListNode(); + + foreach (TreeListNode node in tl_BuyList.Nodes) + { + if (node.GetValue("BuyMarket").ToString() == buyItem.ConGoodsData.CodeFullName) + { + buyNode = node; + break; + } + } + + var moneyVal = (sellVal * (1 - 0.0005) - buyCandleData.BuyValue * (1 - 0.0005)) * result.BuyCount; + + tl_Result.AppendNode(new object[] { + buyNode.GetValue("BuyMarket"), + buyNode.GetValue("BuyValue"), + buyNode.GetValue("BuyCount"), + buyNode.GetValue("BuyDateTime"), + sellVal, + result.SellCount, + time.ToString("yyyy-MM-dd HH:mm:ss"), + result.FirstEarningRate, + moneyVal + }, null); + + lb_BuyMarketCount.Text = buyList.Count.ToString(); + double totalRate = 0; + double totalMoneyValue = 0; + foreach(var resultData in resultDataList) + { + totalRate += resultData.FirstEarningRate; + if (!RealTimeFlag) + { + // 총 돈량 측정 + totalMoneyValue += (resultData.SellValue * (1 - 0.0005) - resultData.BuyValueList[0] * (1 - 0.0005)) * resultData.BuyCount; + } + } + + lb_TotalRate.Text = totalRate + "%"; + + if (!RealTimeFlag) + lb_TotalMoneyValue.Text = totalMoneyValue + "원"; + } + } + #endregion + } + } + + //Stop 시 저장 -> Real Time의 경우 Search Result List만 저장 + if (RealTimeFlag) + { + SaveData(resultDataList); + } + else + { + //이거는 결정해야함 + } + } + /// + /// 데이터 저장 기능 + /// + /// + public void SaveData(List resultDataList) + { + if (resultDataList.Count > 0) + { + _saveResultData.EndDateTime = DateTime.Now; + _saveResultData.SavedDateTime = DateTime.Now; + _saveResultData.SearchResultList = resultDataList; + + //수익 률 계산 로직 -> 이거는 추후 빼도 될듯 + double totalVal = 0; + double win = 0; + double lose = 0; + double firstProfitRate = 0; + double firstWin = 0; + + //승률, 수익률 계산 + foreach (var item in resultDataList) + { + if (item.FirstWinFlag) firstWin++; + + firstProfitRate += item.FirstEarningRate; + win += item.WinCount; + lose += item.LoseCount; + totalVal += item.TotalEarningRate; + } + double winRate; + if (win == 0) + { + winRate = 0; + } + else if (lose == 0) + { + winRate = 100; + } + else + { + winRate = (win * 100 / (win + lose)); + } + + double tt = 0; + double t1 = 0; + foreach (var item in resultDataList) + { + var buy = item.BuyList.CandleDataLists_Im[0]; + var sell = item.SellData; + + tt += ((sell.SellValue - buy.BuyValue) / buy.BuyValue) * 100; + + if (buy.BuyValue < sell.SellValue) t1++; + } + + + tt /= resultDataList.Count; + _saveResultData.ResultDataCount = resultDataList.Count; + _saveResultData.FirstWinRate = (firstWin * 100) / resultDataList.Count; + _saveResultData.FirstProfitRate = firstProfitRate; + _saveResultData.WinRate = winRate; + _saveResultData.ProfitRate = totalVal / resultDataList.Count; + _saveResultData.SearchResultList = resultDataList; + _saveResultData.Name = _saveResultData.SavedDateTime.ToString("yyyy-MM-dd HH:mm:ss") + " Realtime Result"; + _saveResultData.Type = "Data"; + _saveResultData.SaveResultType = "Realtime"; + _saveResultData.ExchangePlace = "Upbit"; + _saveResultData.ParentId = null; + + DBConnection.QueryInsertExcuter_SavedResultData(_saveResultData); + + _saveResultData.StartDateTime = DateTime.Now; + resultDataList.Clear(); + } + MessageBox.Show("데이터 저장 완료"); + } + + /// + /// 데이터 저장 기능 + /// + /// + /// + private void button1_Click(object sender, EventArgs e) + { + SaveData(resultDataList); + } } } diff --git a/Million Buyer/Properties/licenses.licx b/Million Buyer/Properties/licenses.licx index 89458f2..91dc89f 100644 --- a/Million Buyer/Properties/licenses.licx +++ b/Million Buyer/Properties/licenses.licx @@ -1 +1,2 @@ DevExpress.XtraTreeList.TreeList, DevExpress.XtraTreeList.v18.2, Version=18.2.8.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a +DevExpress.XtraEditors.ComboBoxEdit, DevExpress.XtraEditors.v18.2, Version=18.2.8.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a diff --git a/Million Buyer/SubForm/IndicatorLoad.Designer.cs b/Million Buyer/SubForm/IndicatorLoad.Designer.cs index faad2c5..761b7cf 100644 --- a/Million Buyer/SubForm/IndicatorLoad.Designer.cs +++ b/Million Buyer/SubForm/IndicatorLoad.Designer.cs @@ -1,7 +1,7 @@  namespace Million_Buyer.SubForm { - partial class IndicatorLoad + partial class IndicatorLoadForm { /// /// Required designer variable. @@ -29,30 +29,77 @@ namespace Million_Buyer.SubForm /// private void InitializeComponent() { - this.treeList1 = new DevExpress.XtraTreeList.TreeList(); - this.bt_Cancel = new System.Windows.Forms.Button(); - this.bt_Ok = new System.Windows.Forms.Button(); + this.tl_Indicator = new DevExpress.XtraTreeList.TreeList(); this.Id = new DevExpress.XtraTreeList.Columns.TreeListColumn(); - this.Name = new DevExpress.XtraTreeList.Columns.TreeListColumn(); + this.NameField = new DevExpress.XtraTreeList.Columns.TreeListColumn(); this.SavedDateTime = new DevExpress.XtraTreeList.Columns.TreeListColumn(); this.BuyRegularExpression = new DevExpress.XtraTreeList.Columns.TreeListColumn(); this.SellRegularExpression = new DevExpress.XtraTreeList.Columns.TreeListColumn(); - ((System.ComponentModel.ISupportInitialize)(this.treeList1)).BeginInit(); + this.bt_Cancel = new System.Windows.Forms.Button(); + this.bt_Ok = new System.Windows.Forms.Button(); + this.bt_Delete = new System.Windows.Forms.Button(); + this.bt_Modify = new System.Windows.Forms.Button(); + ((System.ComponentModel.ISupportInitialize)(this.tl_Indicator)).BeginInit(); this.SuspendLayout(); // - // treeList1 + // tl_Indicator // - this.treeList1.Columns.AddRange(new DevExpress.XtraTreeList.Columns.TreeListColumn[] { + this.tl_Indicator.Columns.AddRange(new DevExpress.XtraTreeList.Columns.TreeListColumn[] { this.Id, - this.Name, + this.NameField, this.SavedDateTime, this.BuyRegularExpression, this.SellRegularExpression}); - this.treeList1.Cursor = System.Windows.Forms.Cursors.Default; - this.treeList1.Location = new System.Drawing.Point(12, 12); - this.treeList1.Name = "treeList1"; - this.treeList1.Size = new System.Drawing.Size(718, 388); - this.treeList1.TabIndex = 12; + this.tl_Indicator.Cursor = System.Windows.Forms.Cursors.Default; + this.tl_Indicator.Location = new System.Drawing.Point(12, 12); + this.tl_Indicator.Name = "tl_Indicator"; + this.tl_Indicator.Size = new System.Drawing.Size(718, 388); + this.tl_Indicator.TabIndex = 12; + // + // Id + // + this.Id.Caption = "ID"; + this.Id.FieldName = "Id"; + this.Id.Name = "Id"; + this.Id.OptionsColumn.ReadOnly = true; + this.Id.Visible = true; + this.Id.VisibleIndex = 0; + // + // NameField + // + this.NameField.Caption = "Name"; + this.NameField.FieldName = "NameField"; + this.NameField.Name = "NameField"; + this.NameField.OptionsColumn.ReadOnly = true; + this.NameField.Visible = true; + this.NameField.VisibleIndex = 1; + // + // SavedDateTime + // + this.SavedDateTime.Caption = "Save Datetime"; + this.SavedDateTime.FieldName = "SavedDateTime"; + this.SavedDateTime.Name = "SavedDateTime"; + this.SavedDateTime.OptionsColumn.ReadOnly = true; + this.SavedDateTime.Visible = true; + this.SavedDateTime.VisibleIndex = 2; + // + // BuyRegularExpression + // + this.BuyRegularExpression.Caption = "Buy Reg"; + this.BuyRegularExpression.FieldName = "BuyRegularExpression"; + this.BuyRegularExpression.Name = "BuyRegularExpression"; + this.BuyRegularExpression.OptionsColumn.ReadOnly = true; + this.BuyRegularExpression.Visible = true; + this.BuyRegularExpression.VisibleIndex = 3; + // + // SellRegularExpression + // + this.SellRegularExpression.Caption = "Sell Reg"; + this.SellRegularExpression.FieldName = "SellRegularExpression"; + this.SellRegularExpression.Name = "SellRegularExpression"; + this.SellRegularExpression.OptionsColumn.ReadOnly = true; + this.SellRegularExpression.Visible = true; + this.SellRegularExpression.VisibleIndex = 4; // // bt_Cancel // @@ -62,6 +109,7 @@ namespace Million_Buyer.SubForm this.bt_Cancel.TabIndex = 14; this.bt_Cancel.Text = "Cancel"; this.bt_Cancel.UseVisualStyleBackColor = true; + this.bt_Cancel.Click += new System.EventHandler(this.bt_Cancel_Click); // // bt_Ok // @@ -71,71 +119,55 @@ namespace Million_Buyer.SubForm this.bt_Ok.TabIndex = 13; this.bt_Ok.Text = "OK"; this.bt_Ok.UseVisualStyleBackColor = true; + this.bt_Ok.Click += new System.EventHandler(this.bt_Ok_Click); // - // Id + // bt_Delete // - this.Id.Caption = "ID"; - this.Id.FieldName = "Id"; - this.Id.Name = "Id"; - this.Id.Visible = true; - this.Id.VisibleIndex = 0; + this.bt_Delete.Location = new System.Drawing.Point(105, 415); + this.bt_Delete.Name = "bt_Delete"; + this.bt_Delete.Size = new System.Drawing.Size(75, 23); + this.bt_Delete.TabIndex = 15; + this.bt_Delete.Text = "Delete"; + this.bt_Delete.UseVisualStyleBackColor = true; + this.bt_Delete.Click += new System.EventHandler(this.bt_Delete_Click); // - // Name + // bt_Modify // - this.Name.Caption = "Name"; - this.Name.FieldName = "Name"; - this.Name.Name = "Name"; - this.Name.Visible = true; - this.Name.VisibleIndex = 1; + this.bt_Modify.Location = new System.Drawing.Point(12, 415); + this.bt_Modify.Name = "bt_Modify"; + this.bt_Modify.Size = new System.Drawing.Size(75, 23); + this.bt_Modify.TabIndex = 16; + this.bt_Modify.Text = "Modify"; + this.bt_Modify.UseVisualStyleBackColor = true; // - // SavedDateTime - // - this.SavedDateTime.Caption = "Save Datetime"; - this.SavedDateTime.FieldName = "SavedDateTime"; - this.SavedDateTime.Name = "SavedDateTime"; - this.SavedDateTime.Visible = true; - this.SavedDateTime.VisibleIndex = 2; - // - // BuyRegularExpression - // - this.BuyRegularExpression.Caption = "Buy Reg"; - this.BuyRegularExpression.FieldName = "BuyRegularExpression"; - this.BuyRegularExpression.Name = "BuyRegularExpression"; - this.BuyRegularExpression.Visible = true; - this.BuyRegularExpression.VisibleIndex = 3; - // - // SellRegularExpression - // - this.SellRegularExpression.Caption = "Sell Reg"; - this.SellRegularExpression.FieldName = "SellRegularExpression"; - this.SellRegularExpression.Name = "SellRegularExpression"; - this.SellRegularExpression.Visible = true; - this.SellRegularExpression.VisibleIndex = 4; - // - // IndicatorLoad + // IndicatorLoadForm // this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 12F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(742, 450); + this.Controls.Add(this.bt_Modify); + this.Controls.Add(this.bt_Delete); this.Controls.Add(this.bt_Cancel); this.Controls.Add(this.bt_Ok); - this.Controls.Add(this.treeList1); - this.Name = "IndicatorLoad"; + this.Controls.Add(this.tl_Indicator); + this.Name = "IndicatorLoadForm"; this.Text = "IndicatorLoad"; - ((System.ComponentModel.ISupportInitialize)(this.treeList1)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.tl_Indicator)).EndInit(); this.ResumeLayout(false); } #endregion - private DevExpress.XtraTreeList.TreeList treeList1; + private DevExpress.XtraTreeList.TreeList tl_Indicator; private System.Windows.Forms.Button bt_Cancel; private System.Windows.Forms.Button bt_Ok; private DevExpress.XtraTreeList.Columns.TreeListColumn Id; - private DevExpress.XtraTreeList.Columns.TreeListColumn Name; + private DevExpress.XtraTreeList.Columns.TreeListColumn NameField; private DevExpress.XtraTreeList.Columns.TreeListColumn SavedDateTime; private DevExpress.XtraTreeList.Columns.TreeListColumn BuyRegularExpression; private DevExpress.XtraTreeList.Columns.TreeListColumn SellRegularExpression; + private System.Windows.Forms.Button bt_Delete; + private System.Windows.Forms.Button bt_Modify; } } \ No newline at end of file diff --git a/Million Buyer/SubForm/IndicatorLoad.cs b/Million Buyer/SubForm/IndicatorLoad.cs index c140b40..500c802 100644 --- a/Million Buyer/SubForm/IndicatorLoad.cs +++ b/Million Buyer/SubForm/IndicatorLoad.cs @@ -1,4 +1,7 @@ -using System; +using DevExpress.XtraTreeList.Columns; +using Million; +using Million.DbManagement; +using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; @@ -10,11 +13,81 @@ using System.Windows.Forms; namespace Million_Buyer.SubForm { - public partial class IndicatorLoad : Form + public partial class IndicatorLoadForm : Form { - public IndicatorLoad() + public List> datas = null; + int id = 0; + public Dictionary selectData = null; + public IndicatorLoadForm() { InitializeComponent(); + Init(); } + + private void Init() + { + tl_Indicator.ClearNodes(); + + datas = DBConnection.QueryGetExcuter_RealTimeIndicator(); + + if (datas.Count > 0) + { + tl_Indicator.BeginUnboundLoad(); + foreach (var item in datas) + { + tl_Indicator.AppendNode(new object[] + { + item["Id"], + item["Name"], + ((DateTime)item["SavedDateTime"]).ToString("yyyy-MM-dd HH:mm:ss"), + item["BuyRegularExpression"], + item["SellRegularExpression"] + }, null); + } + tl_Indicator.EndUnboundLoad(); + } + } + + /// + /// cancel 버튼 + /// + /// + /// + private void bt_Cancel_Click(object sender, EventArgs e) + { + this.Close(); + } + + /// + /// ok 버튼 + /// + /// + /// + private void bt_Ok_Click(object sender, EventArgs e) + { + try + { + var data = tl_Indicator.Selection.First(); + if (data != null) + { + var strId = data["Id"].ToString(); + selectData = datas.FirstOrDefault(t => t["Id"].ToString() == strId); + this.DialogResult = DialogResult.OK; + } + this.Close(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message); + } + } + + private void bt_Delete_Click(object sender, EventArgs e) + { + var strId = tl_Indicator.Selection.First()["Id"].ToString(); + DBConnection.QueryUpdateExcuter(CommonProperty.DbConnectionResultData, + "DELETE FROM [ResultData].[dbo].[RealTimeIndicator] WHERE Id = " + strId); + Init(); + } } } diff --git a/Million/Data/CandleData.cs b/Million/Data/CandleData.cs index 4314801..26e3a56 100644 --- a/Million/Data/CandleData.cs +++ b/Million/Data/CandleData.cs @@ -20,6 +20,15 @@ namespace Million.Data // 거래량 public double MoneyVolume { get; set; } public double BuyValue { get; set; } + + /// + /// 구매 개수 + /// + public double BuyCount { get; set; } + + public DateTime BuyTime { get; set; } + public DateTime SellTime { get; set; } + public double SellValue { get; set; } public int CandleTimeType { get; set; } public bool RecentlyDataFlag { get; set; } = false; diff --git a/Million/Data/SearchResult.cs b/Million/Data/SearchResult.cs index fc88aca..67e62c1 100644 --- a/Million/Data/SearchResult.cs +++ b/Million/Data/SearchResult.cs @@ -40,6 +40,11 @@ namespace Million.Data public int LoseCount { get; set; } = 0; - + // Buyer에서 사용 + /// + /// 산 개수 + /// + public double BuyCount { get; set; } = 0; + public double SellCount { get; set; } = 0; } } diff --git a/Million/DbMangement/DBConnection.cs b/Million/DbMangement/DBConnection.cs index 308c42e..4df4099 100644 --- a/Million/DbMangement/DBConnection.cs +++ b/Million/DbMangement/DBConnection.cs @@ -76,6 +76,7 @@ namespace Million.DbManagement return marketDatas; } + /// /// Get Candle Data List /// @@ -555,7 +556,53 @@ namespace Million.DbManagement return returnData; } + public static List> QueryGetExcuter_RealTimeIndicator() + { + var returnData = new List>(); + var sqlQuery = "SELECT * FROM [ResultData].[dbo].[RealTimeIndicator]"; + + var strDBCon = CommonProperty.DbConnectionResultData; + using (var conn = new SqlConnection(strDBCon)) + { + using (var cmd = new SqlCommand(sqlQuery, conn)) + { + try + { + conn.Open(); + + using (var rdr = cmd.ExecuteReader()) + { + while (rdr.Read()) + { + var data = new Dictionary(); + data["BuySetupList"] = (List)GetBinaryConvertClass(rdr, "BuySetupList"); + data["SellSetupList"] = (List)GetBinaryConvertClass(rdr, "SellSetupList"); + int.TryParse(rdr["Id"]?.ToString(), out var id); + data["Id"] = id; + data["Name"] = rdr["Name"]?.ToString(); + data["SavedDateTime"] = Convert.ToDateTime(rdr["SavedDateTime"]?.ToString()); + + data["BuyRegularExpression"] = rdr["BuyRegularExpression"]?.ToString(); + data["SellRegularExpression"] = rdr["SellRegularExpression"]?.ToString(); + + returnData.Add(data); + } + } + conn.Close(); + } + catch (Exception ex) + { + Console.WriteLine(" ============= exception ==============="); + Console.WriteLine(ex.Message); + conn.Close(); + return returnData; + } + } + } + + return returnData; + } /// diff --git a/Million/Properties/licenses.licx b/Million/Properties/licenses.licx index 17c6f33..185dd41 100644 --- a/Million/Properties/licenses.licx +++ b/Million/Properties/licenses.licx @@ -1,7 +1,8 @@ -DevExpress.XtraEditors.ButtonEdit, DevExpress.XtraEditors.v18.2, Version=18.2.8.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a -DevExpress.XtraEditors.DateEdit, DevExpress.XtraEditors.v18.2, Version=18.2.8.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a -DevExpress.XtraBars.Ribbon.RibbonControl, DevExpress.XtraBars.v18.2, Version=18.2.8.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a +DevExpress.XtraEditors.TextEdit, DevExpress.XtraEditors.v18.2, Version=18.2.8.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a DevExpress.DashboardWin.DashboardDesigner, DevExpress.Dashboard.v18.2.Win, Version=18.2.8.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a -DevExpress.XtraCharts.ChartControl, DevExpress.XtraCharts.v18.2.UI, Version=18.2.8.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a +DevExpress.XtraBars.Ribbon.RibbonControl, DevExpress.XtraBars.v18.2, Version=18.2.8.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a DevExpress.XtraEditors.ComboBoxEdit, DevExpress.XtraEditors.v18.2, Version=18.2.8.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a +DevExpress.XtraEditors.ButtonEdit, DevExpress.XtraEditors.v18.2, Version=18.2.8.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a DevExpress.XtraTreeList.TreeList, DevExpress.XtraTreeList.v18.2, Version=18.2.8.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a +DevExpress.XtraEditors.DateEdit, DevExpress.XtraEditors.v18.2, Version=18.2.8.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a +DevExpress.XtraCharts.ChartControl, DevExpress.XtraCharts.v18.2.UI, Version=18.2.8.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a