From 8f03c5137fa5f645187e610693a9f7d5ad09ae6d Mon Sep 17 00:00:00 2001 From: mjjo Date: Mon, 27 Mar 2017 10:46:57 +0900 Subject: [PATCH] =?UTF-8?q?=EB=BB=97=EB=8A=94=20=EB=B6=80=EB=B6=84=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AutoSeller.Designer.cs | 83 ++++++++++++++++++++++++------------ AutoSeller.cs | 80 ++++++++++++++-------------------- CybosHelper.cs | 97 +++++++++++++++++++++++++++--------------- SimulationHelper.cs | 93 +++++++++++++++++++++++++++++++++------- Util.cs | 3 ++ 5 files changed, 231 insertions(+), 125 deletions(-) diff --git a/AutoSeller.Designer.cs b/AutoSeller.Designer.cs index c8ef5a2..04d259b 100644 --- a/AutoSeller.Designer.cs +++ b/AutoSeller.Designer.cs @@ -81,6 +81,7 @@ this.tbSMListSize = new System.Windows.Forms.TextBox(); this.tbSMSlowUpCnt = new System.Windows.Forms.TextBox(); this.tbSMTimeDiffLimit = new System.Windows.Forms.TextBox(); + this.tbSMIgnorePrice = new System.Windows.Forms.TextBox(); this.tbSMTimeSub = new System.Windows.Forms.TextBox(); this.tbSMSlowSD = new System.Windows.Forms.TextBox(); this.tbSMFastUpCnt = new System.Windows.Forms.TextBox(); @@ -88,7 +89,6 @@ this.tbSimulationLog = new System.Windows.Forms.RichTextBox(); this.btSimulate = new MaterialSkin.Controls.MaterialFlatButton(); this.btLoad = new MaterialSkin.Controls.MaterialFlatButton(); - this.tbSMIgnorePrice = new System.Windows.Forms.TextBox(); this.lvItems = new AutoSellerNS.ListViewNF(); this.chCode = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); this.chCodeName = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); @@ -103,6 +103,7 @@ this.chCheckCountLimit = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); this.chCheckCount = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); this.lvNCItem = new AutoSellerNS.ListViewNF(); + this.chNCOrgOrderNo = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); this.chNCCode = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); this.chNCCodeName = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); this.chNCType = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); @@ -113,6 +114,7 @@ this.chAskCount = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); this.chCallPrice = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); this.chBidCount = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); + this.chSMHalfTrailing = new MaterialSkin.Controls.MaterialCheckBox(); this.materialTabControl1.SuspendLayout(); this.tabPage1.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.splitContainer2)).BeginInit(); @@ -157,7 +159,7 @@ this.materialTabControl1.MouseState = MaterialSkin.MouseState.HOVER; this.materialTabControl1.Name = "materialTabControl1"; this.materialTabControl1.SelectedIndex = 0; - this.materialTabControl1.Size = new System.Drawing.Size(1141, 719); + this.materialTabControl1.Size = new System.Drawing.Size(1141, 662); this.materialTabControl1.TabIndex = 2; // // tabPage1 @@ -169,7 +171,7 @@ this.tabPage1.Location = new System.Drawing.Point(4, 22); this.tabPage1.Name = "tabPage1"; this.tabPage1.Padding = new System.Windows.Forms.Padding(3); - this.tabPage1.Size = new System.Drawing.Size(1133, 693); + this.tabPage1.Size = new System.Drawing.Size(1133, 636); this.tabPage1.TabIndex = 0; this.tabPage1.Text = "Items"; this.tabPage1.UseVisualStyleBackColor = true; @@ -204,7 +206,7 @@ // splitContainer2.Panel2 // this.splitContainer2.Panel2.Controls.Add(this.lvCurPrice); - this.splitContainer2.Size = new System.Drawing.Size(1127, 655); + this.splitContainer2.Size = new System.Drawing.Size(1127, 598); this.splitContainer2.SplitterDistance = 859; this.splitContainer2.TabIndex = 2; this.splitContainer2.SizeChanged += new System.EventHandler(this.splitContainer2_SizeChanged); @@ -223,8 +225,8 @@ // splitContainer1.Panel2 // this.splitContainer1.Panel2.Controls.Add(this.tbLog); - this.splitContainer1.Size = new System.Drawing.Size(859, 655); - this.splitContainer1.SplitterDistance = 455; + this.splitContainer1.Size = new System.Drawing.Size(859, 598); + this.splitContainer1.SplitterDistance = 415; this.splitContainer1.TabIndex = 1; // // splitContainer3 @@ -241,8 +243,8 @@ // splitContainer3.Panel2 // this.splitContainer3.Panel2.Controls.Add(this.lvNCItem); - this.splitContainer3.Size = new System.Drawing.Size(859, 455); - this.splitContainer3.SplitterDistance = 300; + this.splitContainer3.Size = new System.Drawing.Size(859, 415); + this.splitContainer3.SplitterDistance = 273; this.splitContainer3.TabIndex = 1; // // tbLog @@ -250,7 +252,7 @@ this.tbLog.Dock = System.Windows.Forms.DockStyle.Fill; this.tbLog.Location = new System.Drawing.Point(0, 0); this.tbLog.Name = "tbLog"; - this.tbLog.Size = new System.Drawing.Size(859, 196); + this.tbLog.Size = new System.Drawing.Size(859, 179); this.tbLog.TabIndex = 0; this.tbLog.Text = ""; // @@ -322,7 +324,7 @@ this.tabPage2.Location = new System.Drawing.Point(4, 22); this.tabPage2.Name = "tabPage2"; this.tabPage2.Padding = new System.Windows.Forms.Padding(3); - this.tabPage2.Size = new System.Drawing.Size(1133, 693); + this.tabPage2.Size = new System.Drawing.Size(1133, 636); this.tabPage2.TabIndex = 1; this.tabPage2.Text = "Preference"; // @@ -620,12 +622,12 @@ // this.materialLabel10.AutoSize = true; this.materialLabel10.Depth = 0; - this.materialLabel10.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F); + this.materialLabel10.Font = new System.Drawing.Font("Microsoft Sans Serif", 11F); this.materialLabel10.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(222)))), ((int)(((byte)(0)))), ((int)(((byte)(0)))), ((int)(((byte)(0))))); this.materialLabel10.Location = new System.Drawing.Point(25, 322); this.materialLabel10.MouseState = MaterialSkin.MouseState.HOVER; this.materialLabel10.Name = "materialLabel10"; - this.materialLabel10.Size = new System.Drawing.Size(49, 20); + this.materialLabel10.Size = new System.Drawing.Size(51, 18); this.materialLabel10.TabIndex = 22; this.materialLabel10.Text = "체결 수"; // @@ -720,7 +722,7 @@ this.materialLabel3.Depth = 0; this.materialLabel3.Font = new System.Drawing.Font("Microsoft Sans Serif", 11F); this.materialLabel3.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(222)))), ((int)(((byte)(0)))), ((int)(((byte)(0)))), ((int)(((byte)(0))))); - this.materialLabel3.Location = new System.Drawing.Point(6, 671); + this.materialLabel3.Location = new System.Drawing.Point(6, 614); this.materialLabel3.MouseState = MaterialSkin.MouseState.HOVER; this.materialLabel3.Name = "materialLabel3"; this.materialLabel3.Size = new System.Drawing.Size(162, 18); @@ -813,6 +815,7 @@ // // tabPage3 // + this.tabPage3.Controls.Add(this.chSMHalfTrailing); this.tabPage3.Controls.Add(this.tbSMSlowDownCnt); this.tabPage3.Controls.Add(this.tbSMFastDownCnt); this.tabPage3.Controls.Add(this.cbSMMethod); @@ -830,7 +833,7 @@ this.tabPage3.Location = new System.Drawing.Point(4, 22); this.tabPage3.Name = "tabPage3"; this.tabPage3.Padding = new System.Windows.Forms.Padding(3); - this.tabPage3.Size = new System.Drawing.Size(1133, 693); + this.tabPage3.Size = new System.Drawing.Size(1133, 636); this.tabPage3.TabIndex = 2; this.tabPage3.Text = "Simulation"; this.tabPage3.UseVisualStyleBackColor = true; @@ -888,6 +891,14 @@ this.tbSMTimeDiffLimit.TabIndex = 6; this.tbSMTimeDiffLimit.Text = "5"; // + // tbSMIgnorePrice + // + this.tbSMIgnorePrice.Location = new System.Drawing.Point(333, 128); + this.tbSMIgnorePrice.Name = "tbSMIgnorePrice"; + this.tbSMIgnorePrice.Size = new System.Drawing.Size(59, 21); + this.tbSMIgnorePrice.TabIndex = 6; + this.tbSMIgnorePrice.Text = "50000"; + // // tbSMTimeSub // this.tbSMTimeSub.Location = new System.Drawing.Point(333, 101); @@ -928,7 +939,7 @@ this.tbSimulationLog.HideSelection = false; this.tbSimulationLog.Location = new System.Drawing.Point(0, 204); this.tbSimulationLog.Name = "tbSimulationLog"; - this.tbSimulationLog.Size = new System.Drawing.Size(1133, 489); + this.tbSimulationLog.Size = new System.Drawing.Size(1133, 432); this.tbSimulationLog.TabIndex = 2; this.tbSimulationLog.Text = ""; // @@ -964,14 +975,6 @@ this.btLoad.UseVisualStyleBackColor = true; this.btLoad.Click += new System.EventHandler(this.btLoad_Click); // - // tbSMIgnorePrice - // - this.tbSMIgnorePrice.Location = new System.Drawing.Point(333, 128); - this.tbSMIgnorePrice.Name = "tbSMIgnorePrice"; - this.tbSMIgnorePrice.Size = new System.Drawing.Size(59, 21); - this.tbSMIgnorePrice.TabIndex = 6; - this.tbSMIgnorePrice.Text = "50000"; - // // lvItems // this.lvItems.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] { @@ -992,7 +995,7 @@ this.lvItems.GridLines = true; this.lvItems.Location = new System.Drawing.Point(0, 0); this.lvItems.Name = "lvItems"; - this.lvItems.Size = new System.Drawing.Size(859, 300); + this.lvItems.Size = new System.Drawing.Size(859, 273); this.lvItems.TabIndex = 0; this.lvItems.UseCompatibleStateImageBehavior = false; this.lvItems.View = System.Windows.Forms.View.Details; @@ -1066,6 +1069,7 @@ // lvNCItem // this.lvNCItem.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] { + this.chNCOrgOrderNo, this.chNCCode, this.chNCCodeName, this.chNCType, @@ -1076,11 +1080,16 @@ this.lvNCItem.GridLines = true; this.lvNCItem.Location = new System.Drawing.Point(0, 0); this.lvNCItem.Name = "lvNCItem"; - this.lvNCItem.Size = new System.Drawing.Size(859, 151); + this.lvNCItem.Size = new System.Drawing.Size(859, 138); this.lvNCItem.TabIndex = 1; this.lvNCItem.UseCompatibleStateImageBehavior = false; this.lvNCItem.View = System.Windows.Forms.View.Details; // + // chNCOrgOrderNo + // + this.chNCOrgOrderNo.Text = "원주문번호"; + this.chNCOrgOrderNo.Width = 91; + // // chNCCode // this.chNCCode.Text = "코드"; @@ -1089,7 +1098,7 @@ // chNCCodeName // this.chNCCodeName.Text = "종목명"; - this.chNCCodeName.Width = 86; + this.chNCCodeName.Width = 101; // // chNCType // @@ -1120,7 +1129,7 @@ this.lvCurPrice.GridLines = true; this.lvCurPrice.Location = new System.Drawing.Point(0, 0); this.lvCurPrice.Name = "lvCurPrice"; - this.lvCurPrice.Size = new System.Drawing.Size(264, 655); + this.lvCurPrice.Size = new System.Drawing.Size(264, 598); this.lvCurPrice.TabIndex = 0; this.lvCurPrice.UseCompatibleStateImageBehavior = false; this.lvCurPrice.View = System.Windows.Forms.View.Details; @@ -1146,11 +1155,27 @@ this.chBidCount.TextAlign = System.Windows.Forms.HorizontalAlignment.Right; this.chBidCount.Width = 75; // + // chSMHalfTrailing + // + this.chSMHalfTrailing.AutoSize = true; + this.chSMHalfTrailing.Depth = 0; + this.chSMHalfTrailing.Font = new System.Drawing.Font("Roboto", 10F); + this.chSMHalfTrailing.Location = new System.Drawing.Point(516, 116); + this.chSMHalfTrailing.Margin = new System.Windows.Forms.Padding(0); + this.chSMHalfTrailing.MouseLocation = new System.Drawing.Point(-1, -1); + this.chSMHalfTrailing.MouseState = MaterialSkin.MouseState.HOVER; + this.chSMHalfTrailing.Name = "chSMHalfTrailing"; + this.chSMHalfTrailing.Ripple = true; + this.chSMHalfTrailing.Size = new System.Drawing.Size(100, 30); + this.chSMHalfTrailing.TabIndex = 10; + this.chSMHalfTrailing.Text = "half trailing"; + this.chSMHalfTrailing.UseVisualStyleBackColor = true; + // // AutoSeller // this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 12F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(1147, 837); + this.ClientSize = new System.Drawing.Size(1147, 780); this.Controls.Add(this.materialTabSelector1); this.Controls.Add(this.materialTabControl1); this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon"))); @@ -1264,5 +1289,7 @@ private MaterialSkin.Controls.MaterialLabel materialLabel9; private MaterialSkin.Controls.MaterialLabel materialLabel10; public System.Windows.Forms.TextBox tbSMIgnorePrice; + private System.Windows.Forms.ColumnHeader chNCOrgOrderNo; + public MaterialSkin.Controls.MaterialCheckBox chSMHalfTrailing; } } \ No newline at end of file diff --git a/AutoSeller.cs b/AutoSeller.cs index babde20..6fb48a4 100644 --- a/AutoSeller.cs +++ b/AutoSeller.cs @@ -25,7 +25,6 @@ namespace AutoSellerNS public int m_iAvailableQuantity; public double m_dBookUnitPrice; public long m_iProfitUnitPrice; - public int m_iSellableCnt; public int m_iCurPrice; } @@ -118,27 +117,21 @@ namespace AutoSellerNS if(m_bSell == false) return; - string strLog = ""; - lock(m_NCItems) + var ClonedList = m_NCItems.ConvertAll(s => s); + foreach(var NCItem in ClonedList) { - foreach(var NCItem in m_NCItems) + if(NCItem.m_bAsk == true && DateTime.Now-NCItem.m_Time >= TimeSpan.FromSeconds(5)) { - if(NCItem.m_bAsk == true && DateTime.Now-NCItem.m_Time >= TimeSpan.FromSeconds(5)) - { - var CurItem = m_CybosHelper.GetItem(NCItem.m_strCode); - if(CurItem == null) - continue; + var CurItem = m_CybosHelper.GetItem(NCItem.m_strCode); + if(CurItem == null) + continue; - int iAskPrice = CurItem.m_aiAskPrice[0]; - m_CybosHelper.CorrectionItem(NCItem.m_strCode, NCItem.m_iOrgOrderNo, NCItem.m_iRemainCnt, iAskPrice); - NCItem.m_Time = DateTime.Now; - strLog += (string.Format("[{0}] 정정 주문", NCItem.m_strCodeName) + Environment.NewLine); - } + int iAskPrice = CurItem.m_aiAskPrice[0]; + m_CybosHelper.CorrectionItem(NCItem.m_strCode, NCItem.m_iOrgOrderNo, NCItem.m_iRemainCnt, iAskPrice); + NCItem.m_Time = DateTime.Now; + Util.Log(Util.LOG_TYPE.SELL, string.Format("[{0}] 정정 주문", NCItem.m_strCodeName)); } } - - if(strLog.Length > 0) - Util.Log(Util.LOG_TYPE.SELL, strLog); } public void SetAccountList(string[] aAccountList) @@ -246,7 +239,7 @@ namespace AutoSellerNS m_Items.Clear(); lvItems.Items.Clear(); - foreach (var Item in Items) + foreach(var Item in Items) AddItem(Item); // 미체결 @@ -257,7 +250,7 @@ namespace AutoSellerNS { var NCItems = m_CybosHelper.UpdateNC(); - lock(m_NCItems) + //lock(m_NCItems) { m_NCItems.RemoveAll(s => NCItems.Any(t => t.m_iOrgOrderNo== s.m_iOrgOrderNo) == false); foreach(var NCItem in NCItems) @@ -277,6 +270,7 @@ namespace AutoSellerNS foreach(var NCItem in NCItems) { ListViewItem viewItem = new ListViewItem(new string[] { + NCItem.m_iOrgOrderNo.ToString(), NCItem.m_strCode, NCItem.m_strCodeName, NCItem.m_strDesc, @@ -294,12 +288,13 @@ namespace AutoSellerNS foreach(var NCItem in NCItems) { ListViewItem viewItem = new ListViewItem(new string[] { - NCItem.m_strCode, - NCItem.m_strCodeName, - NCItem.m_strDesc, - string.Format("{0:n0}", NCItem.m_iOrderPrice), - string.Format("{0:n0}", NCItem.m_iRemainCnt), - }); + NCItem.m_iOrgOrderNo.ToString(), + NCItem.m_strCode, + NCItem.m_strCodeName, + NCItem.m_strDesc, + string.Format("{0:n0}", NCItem.m_iOrderPrice), + string.Format("{0:n0}", NCItem.m_iRemainCnt), + }); lvNCItem.Items.Add(viewItem); viewItem.UseItemStyleForSubItems = false; viewItem.SubItems[chNCType.Index].ForeColor = NCItem.m_bAsk ? Color.Blue : Color.Red; @@ -309,28 +304,16 @@ namespace AutoSellerNS public void UpdateItem(string strCode, string strCodeName, bool bBid, int iConclusionCnt, int iRemainCnt, int iBookValue) { - btUpdate_Click(null, null); - //if(lvList.InvokeRequired) - //{ + // 잔고 + var Items = m_CybosHelper.UpdateItems(); - //} - //else - //{ - // ListViewItem Item = lvList.Items.Cast().FirstOrDefault(s => s.SubItems[chCode.Index].Text == strCode); - // if(Item == default(ListViewItem) && iRemainCnt > 0) - // { - // // 아이템 추가 - // } - // else - // { - // // 갱신 - // Item.SubItems[chCount.Index].Text = string.Format("{0:n0}", iRemainCnt); - // Item.SubItems[chBookValue.Index].Text = string.Format("{0:n2}", iBookValue); - // } - //} + m_Items.Clear(); + lvItems.Items.Clear(); + foreach(var Item in Items) + AddItem(Item); } - public void OnReceipt() + public void UpdateNCItem() { UpdateNC(); } @@ -353,8 +336,9 @@ namespace AutoSellerNS return; Item.m_iCurPrice = iPrice; - Item.m_iAssessedValue = (int)(iPrice * Item.m_iAvailableQuantity * 99.94 / 100); - Item.m_dYield = (Item.m_iCurPrice - Item.m_iProfitUnitPrice) * 100 / (double)Item.m_iProfitUnitPrice; + Item.m_iAssessedValue = iPrice * Item.m_iItemCnt; + Item.m_iValuationGains = (iPrice-Item.m_iProfitUnitPrice)*Item.m_iItemCnt; + Item.m_dYield = (iPrice-Item.m_iProfitUnitPrice)*100 / (double)Item.m_iProfitUnitPrice; if (lvItems.InvokeRequired) { @@ -366,6 +350,7 @@ namespace AutoSellerNS row.SubItems[chCurPrice.Index].Text = string.Format("{0}{1:n0}", bReal?"":"*", Item.m_iCurPrice); row.SubItems[chAssessedValue.Index].Text = string.Format("{0:n0}", Item.m_iAssessedValue); + row.SubItems[chValuation.Index].Text = string.Format("{0:n0}", Item.m_iValuationGains); row.SubItems[chYield.Index].Text = string.Format("{0:n2}", Item.m_dYield); row.SubItems[chMaxPrice.Index].Text = string.Format("{0:n0}", iMaxPrice); row.SubItems[chCheckCountLimit.Index].Text = string.Format("{0:n2}", dCheckCountLimit); @@ -380,6 +365,7 @@ namespace AutoSellerNS row.SubItems[chCurPrice.Index].Text = string.Format("{0}{1:n0}", bReal?"":"*", Item.m_iCurPrice); row.SubItems[chAssessedValue.Index].Text = string.Format("{0:n0}", Item.m_iAssessedValue); + row.SubItems[chValuation.Index].Text = string.Format("{0:n0}", Item.m_iValuationGains); row.SubItems[chYield.Index].Text = string.Format("{0:n2}", Item.m_dYield); row.SubItems[chMaxPrice.Index].Text = string.Format("{0:n0}", iMaxPrice); row.SubItems[chCheckCountLimit.Index].Text = string.Format("{0:n2}", dCheckCountLimit); @@ -455,7 +441,7 @@ namespace AutoSellerNS if(Item == default(ITEM)) return 0; - return Item.m_iSellableCnt; + return Item.m_iAvailableQuantity; } private void lvList_SelectedIndexChanged(object sender, EventArgs e) diff --git a/CybosHelper.cs b/CybosHelper.cs index e98d4b6..2853941 100644 --- a/CybosHelper.cs +++ b/CybosHelper.cs @@ -107,7 +107,7 @@ namespace AutoSellerNS m_iMaxPrice)); } - if(iTimeDiff >= Config.GetTimeLimit()) + if(iTimeDiff >= Config.GetTimeLimit() && m_Listener.IsSelling() == true) { m_CybosHelper.SellItem(m_strCode, m_Listener.GetSellableCount(m_strCode), m_aiAskPrice[0]); Util.Log(Util.LOG_TYPE.SELL, string.Format("[시간제한 매도] {0} ({1}초) (현재가 {2:n0}원, 최고가 {3:n0}원)", @@ -223,7 +223,6 @@ namespace AutoSellerNS Item.m_iAvailableQuantity = m_6033.GetDataValue(15, i); Item.m_dBookUnitPrice = m_6033.GetDataValue(17, i); Item.m_iProfitUnitPrice = m_6033.GetDataValue(18, i); - Item.m_iSellableCnt = m_6033.GetDataValue(15, i); if(strCodeList.Length > 0) strCodeList += ","; @@ -242,7 +241,7 @@ namespace AutoSellerNS { DSCBO1Lib.StockMst2 StockMst = new DSCBO1Lib.StockMst2(); StockMst.SetInputValue(0, strCodeList); - StockMst.BlockRequest2(0); + StockMst.BlockRequest2(1); int iCnt = StockMst.GetHeaderValue(0); for (int i = 0; i < iCnt; i++) { @@ -272,43 +271,54 @@ namespace AutoSellerNS return aItems; } + static int iUpdateNCIdx = 1; public List UpdateNC() { + int iIdx = iUpdateNCIdx++; + Util.Log(Util.LOG_TYPE.DEBUG, string.Format("UpdateNC Start ({0}, {1}, {2}, {3})", iIdx, + GetLimitRemainCountRQ(), GetLimitRemainCountSB(), GetLimitRemainCountTrade() + )); + + while(GetLimitRemainCountTrade() < 1) + Thread.Sleep(500); + List NCItems = new List(); - lock(m_NCItemLock) + + CPTRADELib.CpTd5339 CP5339 = new CPTRADELib.CpTd5339(); + CP5339.SetInputValue(0, Config.GetAccount()); + CP5339.SetInputValue(1, Config.GetSubAccount()); + CP5339.BlockRequest2(1); + + bool bContinue = true; + while(bContinue) { - CPTRADELib.CpTd5339 CP5339 = new CPTRADELib.CpTd5339(); - CP5339.SetInputValue(0, Config.GetAccount()); - CP5339.SetInputValue(1, Config.GetSubAccount()); - CP5339.BlockRequest2(0); + int iCnt = CP5339.GetHeaderValue(5); + Console.WriteLine("icnt : {0}", iCnt); - bool bContinue = true; - while(bContinue) + for(int i = 0; i aaRows = new List(); @@ -262,7 +262,7 @@ namespace AutoSellerNS { while(m_CybosHelper.GetLimitRemainCountRQ() < 2) Thread.Sleep(100); - CPStockBid.BlockRequest2(0); + CPStockBid.BlockRequest2(1); } m_tbLogView.AppendText(string.Format("RequestRQ({0}) ", m_CybosHelper.GetLimitRemainCountRQ())); @@ -450,6 +450,7 @@ namespace AutoSellerNS double dTimeSub = (double)aParams[10]; int iTimeDiffLimit = (int)aParams[11]; int iIgnorePrice = (int)aParams[12]; + bool bHalfTrailing = (bool)aParams[13]; var tokens = strLine.Split('\t'); @@ -521,7 +522,7 @@ namespace AutoSellerNS int iPrice = (int)(double)Sheet.Cells[iRow, 3].Value; int iAskPrice = (int)(double)Sheet.Cells[iRow, 4].Value; int iBidPrice = (int)(double)Sheet.Cells[iRow, 5].Value; - int iConclusionCnt = (int)(double)Sheet.Cells[iRow, 8].Value; + int iConclusionCnt = (int)(double)Sheet.Cells[iRow, 7].Value; int iTimeDiff = 0; if(iPrevTime > 0) @@ -661,7 +662,7 @@ namespace AutoSellerNS if(iAskCount >= Math.Round(dCheckCount)) { iSellPrice = iPrice - m_CybosHelper.GetUnitValue(iPrice); - strReturnMsg = string.Format("[{0}] [{1}] 조건1 매도 (매수: {2:n0}원, {3}, line:{4}) (매도: {5:n0}원(매도가:{6:n0}원) {7} line:{8}) (손익: {9}, {10:n0} : {11:n2}%) {12} \n", + strReturnMsg = string.Format("[{0}] [{1}] 조건 매도\n\t\t매수: {2:n0}원, {3}, line:{4}\n\t\t매도: {5:n0}원(매도가:{6:n0}원) {7} line:{8} (최고가: {9:n0})\n\t\t손익: {10}, {11:n0} : {12:n2}% ({13:n2}) \n", StartDT.ToString("yyyy-MM-dd"), strCodeName, @@ -673,6 +674,7 @@ namespace AutoSellerNS iSellPrice, RowDT.ToString("HH:mm:ss"), iRow, + iMaxPrice, iSellPrice-iStartPrice, (iSellPrice-iStartPrice)*iStockCount, @@ -705,7 +707,7 @@ namespace AutoSellerNS if(iTrailingCount >= Config.GetTrailingCnt()) { iSellPrice = iPrice - m_CybosHelper.GetUnitValue(iPrice); - strReturnMsg = string.Format("[{0}] [{1}] 트레일링 매도 (매수: {2:n0}원, {3}, line:{4}) (매도: {5:n0}원(매도가:{6:n0}원) {7} line:{8}) (손익: {9}, {10:n0} : {11:n2}%) {12} \n", + strReturnMsg = string.Format("[{0}] [{1}] 트레일링 매도 \n\t\t매수: {2:n0}원, {3}, line:{4}\n\t\t매도: {5:n0}원(매도가:{6:n0}원) {7} line:{8} (최고가: {9:n0})\n\t\t손익: {10}, {11:n0} : {12:n2}% ({13:n2}) \n", StartDT.ToString("yyyy-MM-dd"), strCodeName, @@ -717,6 +719,7 @@ namespace AutoSellerNS iSellPrice, RowDT.ToString("HH:mm:ss"), iRow, + iMaxPrice, iSellPrice-iStartPrice, (iSellPrice-iStartPrice)*iStockCount, @@ -735,10 +738,10 @@ namespace AutoSellerNS break; } - if(iTimeDiff >= iTimeDiffLimit) + if(bHalfTrailing == true && iMaxPrice/(float)iStartPrice >= 1.02 && iPrice < (iStartPrice+iMaxPrice)/2) { iSellPrice = iPrice - m_CybosHelper.GetUnitValue(iPrice); - strReturnMsg = string.Format("[{0}] [{1}] 제한시간 매도 (매수: {2:n0}원, {3}, line:{4}) (매도: {5:n0}원(매도가:{6:n0}원) {7} line:{8}) (손익: {9}, {10:n0} : {11:n2}%) {12} \n", + strReturnMsg = string.Format("[{0}] [{1}] 트레일링2 매도\n\t\t매수: {2:n0}원, {3}, line:{4}\n\t\t매도: {5:n0}원(매도가:{6:n0}원 {7} line:{8} (최고가: {9:n0})\n\t\t손익: {10}, {11:n0} : {12:n2}%) ({13:n2}) \n", StartDT.ToString("yyyy-MM-dd"), strCodeName, @@ -750,6 +753,61 @@ namespace AutoSellerNS iSellPrice, RowDT.ToString("HH:mm:ss"), iRow, + iMaxPrice, + + iSellPrice-iStartPrice, + (iSellPrice-iStartPrice)*iStockCount, + (iSellPrice-iStartPrice)*100/(float)iStartPrice, + + dCheckCount + + ); + + break; + } + + double dSlope = 0; + if(m_PriceList.Count >= 5) + { + List LastSample = new List(); + for(int i = 0; i<5; i++) + { + Point Pos = new Point(); + Pos.X = m_PriceList[m_PriceList.Count-i-1]; + Pos.X = Pos.X/m_CybosHelper.GetUnitValue(Pos.X); + + Pos.Y = 5-i; + + LastSample.Add(Pos); + } + + double xBar = LastSample.Average(p => p.X); + double yBar = LastSample.Average(p => p.Y); + + double dividend = LastSample.Sum(p => (p.X - xBar) * (p.Y - yBar)); + double divisor = (double)LastSample.Sum(p => Math.Pow(p.X - xBar, 2)); + + dSlope = dividend / divisor; + Sheet.Cells[iRow, 13].Value = dSlope; + } + + + if(iTimeDiff >= iTimeDiffLimit) + { + iSellPrice = iPrice - m_CybosHelper.GetUnitValue(iPrice); + strReturnMsg = string.Format("[{0}] [{1}] 제한시간 매도\n\t\t매수: {2:n0}원, {3}, line:{4}\n\t\t매도: {5:n0}원(매도가:{6:n0}원) {7} line:{8} (최고가: {9:n0})\n\t\t손익: {10}, {11:n0} : {12:n2}%) ({13:n2}) \n", + StartDT.ToString("yyyy-MM-dd"), + strCodeName, + + iStartPrice, + StartDT.ToString("HH:mm:ss"), + iStartRow, + + iPrice, + iSellPrice, + RowDT.ToString("HH:mm:ss"), + iRow, + iMaxPrice, iSellPrice-iStartPrice, (iSellPrice-iStartPrice)*iStockCount, @@ -774,7 +832,7 @@ namespace AutoSellerNS if(iRow == iMaxRow) { iSellPrice = iPrice - m_CybosHelper.GetUnitValue(iPrice); - strReturnMsg = string.Format("[{0}] [{1}] 종료 매도 (매수: {2:n0}원, {3}, line:{4}) (매도: {5:n0}원(매도가:{6:n0}원) {7} line:{8}) (손익: {9}, {10:n0} : {11:n2}%) {12} \n", + strReturnMsg = string.Format("[{0}] [{1}] 종료 매도\n\t\t매수: {2:n0}원, {3}, line:{4}\n\t\t매도: {5:n0}원(매도가:{6:n0}원) {7} line:{8} (최고가: {9:n0})\n\t\t손익: {10}, {11:n0} : {12:n2}%) ({13:n2}) \n", StartDT.ToString("yyyy-MM-dd"), strCodeName, @@ -841,11 +899,12 @@ namespace AutoSellerNS double dTimeSub = (double)aParams[9]; int iTimeDiffLimit = (int)aParams[10]; int iIgnorePrice = (int)aParams[11]; + bool bHalfTrailing = (bool)aParams[12]; - InsertLog(string.Format("[시뮬레이션 시작] 조건 : {0}회, 트레일링 : {1}%, {2}회\n \t\t리스트 크기:{3}, Fast : {4}, {5}, {6}, Slow : {7}, {8}, {9}, 초당 {10} 감소, 제한 시간: {11}, {12}원 이하 무시, 비교 방식 : {13}\n", + InsertLog(string.Format("[시뮬레이션 시작] 조건 : {0}회, 트레일링 : {1}%, {2}회\n\t\t리스트 크기:{3}, Fast : {4}, {5}, {6}, Slow : {7}, {8}, {9}, 초당 {10} 감소, 제한 시간: {11}, {12}원 이하 무시, \n\t\t트레일링2 : {13}, 비교 방식 : {14}\n", Config.GetBidCount(), Config.GetTrailingRate(), Config.GetTrailingCnt(), iListCnt, dFastSD, dFastUpCnt, dFastDownCnt, dSlowSD, dSlowUpCnt, dSlowDownCnt, - dTimeSub, iTimeDiffLimit, iIgnorePrice, + dTimeSub, iTimeDiffLimit, iIgnorePrice, bHalfTrailing, strMethod )); @@ -861,7 +920,7 @@ namespace AutoSellerNS dSlowSD, dSlowUpCnt, dSlowDownCnt, iCompareType, strMethod, strLine, dTimeSub, iTimeDiffLimit, - iIgnorePrice })); + iIgnorePrice, bHalfTrailing })); aTasks.Add(task); } @@ -891,6 +950,7 @@ namespace AutoSellerNS double dTimeSub; int iTimeDiffLimit; int iIgnorePrice; + bool bHalfTrailing; int.TryParse(m_AutoSeller.tbSMListSize.Text, out iListCnt); double.TryParse(m_AutoSeller.tbSMFastSD.Text, out dFastSD); @@ -902,6 +962,7 @@ namespace AutoSellerNS double.TryParse(m_AutoSeller.tbSMTimeSub.Text, out dTimeSub); int.TryParse(m_AutoSeller.tbSMTimeDiffLimit.Text, out iTimeDiffLimit); int.TryParse(m_AutoSeller.tbSMIgnorePrice.Text, out iIgnorePrice); + bHalfTrailing = m_AutoSeller.chSMHalfTrailing.Checked; string strMethod = ""; m_AutoSeller.cbSMMethod.Invoke(new Action(() => { @@ -931,7 +992,7 @@ namespace AutoSellerNS dFastSD, dFastUpCnt, dFastDownCnt, dSlowSD, dSlowUpCnt, dSlowDownCnt, iCompareType, strMethod, dTimeSub, iTimeDiffLimit, - iIgnorePrice + iIgnorePrice, bHalfTrailing }); // } // } diff --git a/Util.cs b/Util.cs index 5851e50..dc20a63 100644 --- a/Util.cs +++ b/Util.cs @@ -39,6 +39,9 @@ namespace AutoSellerNS static void InsertLog(RichTextBox LogBox, LOG_TYPE enType, string strLog) { + if(IsDebugging() == false && enType == LOG_TYPE.DEBUG) + return; + if(LogBox.InvokeRequired) { LogBox.Invoke(m_InsertLogDelegate, LogBox, enType, strLog);