뻗는 부분 수정

This commit is contained in:
2017-03-27 10:46:57 +09:00
parent 24fe10afd8
commit 8f03c5137f
5 changed files with 231 additions and 125 deletions

83
AutoSeller.Designer.cs generated
View File

@@ -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;
}
}

View File

@@ -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<ListViewItem>().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)

View File

@@ -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<AutoSeller.NCITEM> 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<AutoSeller.NCITEM> NCItems = new List<AutoSeller.NCITEM>();
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<iCnt; i++)
{
int iCnt = CP5339.GetHeaderValue(5);
for(int i = 0; i<iCnt; i++)
{
AutoSeller.NCITEM Item = new AutoSeller.NCITEM();
AutoSeller.NCITEM Item = new AutoSeller.NCITEM();
Item.m_strCode = CP5339.GetDataValue(3, i);
Item.m_strCodeName = CP5339.GetDataValue(4, i);
Item.m_strDesc = CP5339.GetDataValue(5, i);
Item.m_iOrderPrice = CP5339.GetDataValue(7, i);
Item.m_iRemainCnt = CP5339.GetDataValue(11, i);
Item.m_bAsk = (CP5339.GetDataValue(13, i) == "1");
Item.m_iOrgOrderNo = CP5339.GetDataValue(2, i);
if(Item.m_iOrgOrderNo == 0)
Item.m_iOrgOrderNo = CP5339.GetDataValue(1, i);
Item.m_strCode = CP5339.GetDataValue(3, i);
Item.m_strCodeName = CP5339.GetDataValue(4, i);
Item.m_strDesc = CP5339.GetDataValue(5, i);
Item.m_iOrderPrice = CP5339.GetDataValue(7, i);
Item.m_iRemainCnt = CP5339.GetDataValue(11, i);
Item.m_bAsk = (CP5339.GetDataValue(13, i) == "1");
Item.m_iOrgOrderNo = CP5339.GetDataValue(2, i);
if(Item.m_iOrgOrderNo == 0)
Item.m_iOrgOrderNo = CP5339.GetDataValue(1, i);
NCItems.Add(Item);
}
bContinue = (CP5339.Continue != 0);
if(bContinue)
CP5339.BlockRequest2(0);
NCItems.Add(Item);
}
bContinue = (CP5339.Continue != 0);
if(bContinue)
CP5339.BlockRequest2(1);
}
Util.Log(Util.LOG_TYPE.DEBUG, string.Format("UpdateNC End ({0})", iIdx));
return NCItems;
}
@@ -332,6 +342,7 @@ namespace AutoSellerNS
{
case 1: // 체결
m_Listener.UpdateItem(strCode, strCodeName, bBid, iConclusionCnt, iRemainCnt, iBookValue);
m_Listener.UpdateNCItem();
Util.Log(bBid?Util.LOG_TYPE.BUY:Util.LOG_TYPE.SELL, string.Format("{0}:{1} {2} 체결 ({3:n0}원 {4}주)", strCodeName, strCode, strBidOrAsk, iPrice, iConclusionCnt));
break;
@@ -344,7 +355,7 @@ namespace AutoSellerNS
break;
case 4: // 접수
m_Listener.OnReceipt();
m_Listener.UpdateNCItem();
Util.Log(bBid ? Util.LOG_TYPE.BUY : Util.LOG_TYPE.SELL, string.Format("{0}:{1} {2} 접수 ({3:n0}원 {4}주)", strCodeName, strCode, strBidOrAsk, iPrice, iConclusionCnt));
break;
}
@@ -390,7 +401,7 @@ namespace AutoSellerNS
DSCBO1Lib.StockJpbid2 JpBid = new DSCBO1Lib.StockJpbid2();
JpBid.SetInputValue(0, Item.m_strCode);
JpBid.BlockRequest2(0);
JpBid.BlockRequest2(1);
for(int i=0; i<10; i++)
{
StockCur.m_aiAskPrice[i] = JpBid.GetDataValue(0, i);
@@ -440,8 +451,12 @@ namespace AutoSellerNS
return (iValue/iUnit)*iUnit;
}
static int iSellIdx = 1;
public void SellItem(string strCode, int iCnt, int iAskPrice)
{
int iIdx = iSellIdx++;
Util.Log(Util.LOG_TYPE.DEBUG, string.Format("SellItem Start ({0})", iIdx));
int iSellPrice = iAskPrice-GetUnitValue(iAskPrice);
CPTRADELib.CpTd0311 Td0311 = new CPTRADELib.CpTd0311();
@@ -452,22 +467,34 @@ namespace AutoSellerNS
Td0311.SetInputValue(4, iCnt);
Td0311.SetInputValue(5, iSellPrice);
Td0311.SetInputValue(8, "01");
Td0311.BlockRequest2(0);
Td0311.BlockRequest2(1);
Util.Log(Util.LOG_TYPE.DEBUG, string.Format("SellItem End ({0})", iIdx));
}
static int iCancelIdx = 1;
public void CancelItem(string strCode, int iOrgOrderNo)
{
int iIdx = iCancelIdx++;
Util.Log(Util.LOG_TYPE.DEBUG, string.Format("CancelItem Start ({0})", iIdx));
CPTRADELib.CpTd0314 Td0314 = new CPTRADELib.CpTd0314();
Td0314.SetInputValue(1, iOrgOrderNo);
Td0314.SetInputValue(2, Config.GetAccount());
Td0314.SetInputValue(3, Config.GetSubAccount());
Td0314.SetInputValue(4, strCode);
Td0314.SetInputValue(5, 0);
Td0314.BlockRequest2(0);
Td0314.BlockRequest2(1);
Util.Log(Util.LOG_TYPE.DEBUG, string.Format("CancelItem End ({0})", iIdx));
}
static int iCorrectIdx = 1;
public void CorrectionItem(string strCode, int iOrgOrderNo, int iCnt, int iAskPrice)
{
int iIdx = iCorrectIdx++;
Util.Log(Util.LOG_TYPE.DEBUG, string.Format("CorrectionItem Start ({0})", iIdx));
int iSellPrice = iAskPrice-GetUnitValue(iAskPrice);
//CancelItem(strCode, iOrgOrderNo);
@@ -481,7 +508,9 @@ namespace AutoSellerNS
Td0313.SetInputValue(4, strCode);
Td0313.SetInputValue(5, 0);
Td0313.SetInputValue(6, iSellPrice);
Td0313.BlockRequest2(0);
Td0313.BlockRequest2(1);
Util.Log(Util.LOG_TYPE.DEBUG, string.Format("CorrectionItem End ({0})", iIdx));
}
}
}

View File

@@ -59,7 +59,7 @@ namespace AutoSellerNS
// CPStockChart.SetInputValue(4, 100000);
// CPStockChart.SetInputValue(5, new int[] { 0, 1, 5, 8, 9, 10, 11 });
// CPStockChart.SetInputValue(6, 'T');
// CPStockChart.BlockRequest2(0);
// CPStockChart.BlockRequest2(1);
// int iFieldCnt = CPStockChart.GetHeaderValue(1);
// string[] astrFieldName = CPStockChart.GetHeaderValue(2);
@@ -96,7 +96,7 @@ namespace AutoSellerNS
// bContinue = (CPStockChart.Continue==1);
// if(bContinue == true)
// CPStockChart.BlockRequest2(0);
// CPStockChart.BlockRequest2(1);
// m_tbLogView.AppendText(string.Format("RequestRQ({0}) ", m_CybosHelper.GetLimitRemainCountRQ()));
// }
@@ -149,7 +149,7 @@ namespace AutoSellerNS
// CPStockChart.SetInputValue(3, StartDT.ToString("yyyyMMdd"));
// CPStockChart.SetInputValue(5, new int[] { 0, 1, 5, 8, 9, 10, 11 });
// CPStockChart.SetInputValue(6, 'T');
// CPStockChart.BlockRequest2(0);
// CPStockChart.BlockRequest2(1);
// int iFieldCnt = CPStockChart.GetHeaderValue(1);
// string[] astrFieldName = CPStockChart.GetHeaderValue(2);
@@ -184,7 +184,7 @@ namespace AutoSellerNS
// bContinue = (CPStockChart.Continue==1);
// if(bContinue == true)
// CPStockChart.BlockRequest2(0);
// CPStockChart.BlockRequest2(1);
// m_tbLogView.AppendText(string.Format("RequestRQ({0}) ", m_CybosHelper.GetLimitRemainCountRQ()));
// }
@@ -236,7 +236,7 @@ namespace AutoSellerNS
CPStockBid.SetInputValue(2, 20000);
CPStockBid.SetInputValue(3, 'C');
CPStockBid.SetInputValue(4, "2000");
CPStockBid.BlockRequest2(0);
CPStockBid.BlockRequest2(1);
List<object[]> aaRows = new List<object[]>();
@@ -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<Point> LastSample = new List<Point>();
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
});
// }
// }

View File

@@ -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);