Compare commits

...

6 Commits

Author SHA1 Message Date
e7cae78682 Merge branch 'master' of ssh://mjjo53.us.to:10022/trade/AutoSeller 2018-12-26 16:14:13 +09:00
67924744e1 탭 안보이는 문제 2018-12-26 16:14:07 +09:00
c2fe80ab22 탭 안보이는 문제 2018-12-26 16:13:23 +09:00
9493b9f4d5 update 2018-12-04 23:24:02 +09:00
22b38609cd auto cancel 2018-10-16 19:55:21 +09:00
7197272479 - 마감 전 청산
- 미체결 취소 버튼
- TR lock
2018-10-16 13:38:25 +09:00
8 changed files with 505 additions and 109 deletions

163
AutoSeller.Designer.cs generated
View File

@@ -32,6 +32,7 @@
this.materialTabSelector1 = new MaterialSkin.Controls.MaterialTabSelector();
this.materialTabControl1 = new MaterialSkin.Controls.MaterialTabControl();
this.tabPage1 = new System.Windows.Forms.TabPage();
this.btClearBeforeClosing = new MaterialSkin.Controls.MaterialRaisedButton();
this.btClearAll = new MaterialSkin.Controls.MaterialRaisedButton();
this.lbRQCnt = new MaterialSkin.Controls.MaterialLabel();
this.lbTRCnt = new MaterialSkin.Controls.MaterialLabel();
@@ -41,6 +42,7 @@
this.splitContainer1 = new System.Windows.Forms.SplitContainer();
this.splitContainer3 = new System.Windows.Forms.SplitContainer();
this.splitContainer4 = new System.Windows.Forms.SplitContainer();
this.btCancel = new MaterialSkin.Controls.MaterialRaisedButton();
this.btUpdateNC = new MaterialSkin.Controls.MaterialRaisedButton();
this.tbLog = new System.Windows.Forms.RichTextBox();
this.btUpdate = new MaterialSkin.Controls.MaterialRaisedButton();
@@ -52,8 +54,16 @@
this.columnHeader3 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.columnHeader4 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.columnHeader5 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.columnHeader6 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.columnHeader7 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.columnHeader8 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.columnHeader9 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.columnHeader10 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.tabPage3 = new System.Windows.Forms.TabPage();
this.cbMockTrading = new System.Windows.Forms.CheckBox();
this.materialLabel19 = new MaterialSkin.Controls.MaterialLabel();
this.tbAutoCancelDelay = new MaterialSkin.Controls.MaterialSingleLineTextField();
this.cbAutoCancel = new MaterialSkin.Controls.MaterialCheckBox();
this.cbMockTrading = new MaterialSkin.Controls.MaterialCheckBox();
this.materialLabel18 = new MaterialSkin.Controls.MaterialLabel();
this.tbCFIgnorePrice = new MaterialSkin.Controls.MaterialSingleLineTextField();
this.materialLabel17 = new MaterialSkin.Controls.MaterialLabel();
@@ -104,11 +114,6 @@
this.tbSimulationLog = new System.Windows.Forms.RichTextBox();
this.btSimulate = new MaterialSkin.Controls.MaterialFlatButton();
this.btLoad = new MaterialSkin.Controls.MaterialFlatButton();
this.columnHeader6 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.columnHeader7 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.columnHeader8 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.columnHeader9 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.columnHeader10 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
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()));
@@ -177,9 +182,9 @@
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.materialTabControl1.Controls.Add(this.tabPage1);
this.materialTabControl1.Controls.Add(this.tabPage2);
this.materialTabControl1.Controls.Add(this.tabPage3);
this.materialTabControl1.Controls.Add(this.tabPage4);
this.materialTabControl1.Controls.Add(this.tabPage2);
this.materialTabControl1.Depth = 0;
this.materialTabControl1.Location = new System.Drawing.Point(3, 115);
this.materialTabControl1.MouseState = MaterialSkin.MouseState.HOVER;
@@ -190,6 +195,7 @@
//
// tabPage1
//
this.tabPage1.Controls.Add(this.btClearBeforeClosing);
this.tabPage1.Controls.Add(this.btClearAll);
this.tabPage1.Controls.Add(this.lbRQCnt);
this.tabPage1.Controls.Add(this.lbTRCnt);
@@ -206,6 +212,20 @@
this.tabPage1.Text = "Items";
this.tabPage1.UseVisualStyleBackColor = true;
//
// btClearBeforeClosing
//
this.btClearBeforeClosing.AutoSize = true;
this.btClearBeforeClosing.Depth = 0;
this.btClearBeforeClosing.Location = new System.Drawing.Point(782, 3);
this.btClearBeforeClosing.MouseState = MaterialSkin.MouseState.HOVER;
this.btClearBeforeClosing.Name = "btClearBeforeClosing";
this.btClearBeforeClosing.Primary = true;
this.btClearBeforeClosing.Size = new System.Drawing.Size(128, 28);
this.btClearBeforeClosing.TabIndex = 9;
this.btClearBeforeClosing.Text = "Close Closing";
this.btClearBeforeClosing.UseVisualStyleBackColor = true;
this.btClearBeforeClosing.Click += new System.EventHandler(this.btClearBeforeClosing_Click);
//
// btClearAll
//
this.btClearAll.AutoSize = true;
@@ -342,11 +362,26 @@
//
// splitContainer4.Panel2
//
this.splitContainer4.Panel2.Controls.Add(this.btCancel);
this.splitContainer4.Panel2.Controls.Add(this.btUpdateNC);
this.splitContainer4.Size = new System.Drawing.Size(859, 138);
this.splitContainer4.SplitterDistance = 772;
this.splitContainer4.TabIndex = 2;
//
// btCancel
//
this.btCancel.AutoSize = true;
this.btCancel.Depth = 0;
this.btCancel.Location = new System.Drawing.Point(2, 37);
this.btCancel.MouseState = MaterialSkin.MouseState.HOVER;
this.btCancel.Name = "btCancel";
this.btCancel.Primary = true;
this.btCancel.Size = new System.Drawing.Size(77, 28);
this.btCancel.TabIndex = 4;
this.btCancel.Text = "Cancel";
this.btCancel.UseVisualStyleBackColor = true;
this.btCancel.Click += new System.EventHandler(this.btCancel_Click);
//
// btUpdateNC
//
this.btUpdateNC.AutoSize = true;
@@ -463,9 +498,32 @@
//
this.columnHeader5.Text = "약정금액";
//
// columnHeader6
//
this.columnHeader6.Text = "정산금액";
//
// columnHeader7
//
this.columnHeader7.Text = "수수료";
//
// columnHeader8
//
this.columnHeader8.Text = "거래세";
//
// columnHeader9
//
this.columnHeader9.Text = "농특세";
//
// columnHeader10
//
this.columnHeader10.Text = "날짜";
//
// tabPage3
//
this.tabPage3.BackColor = System.Drawing.Color.White;
this.tabPage3.Controls.Add(this.materialLabel19);
this.tabPage3.Controls.Add(this.tbAutoCancelDelay);
this.tabPage3.Controls.Add(this.cbAutoCancel);
this.tabPage3.Controls.Add(this.cbMockTrading);
this.tabPage3.Controls.Add(this.materialLabel18);
this.tabPage3.Controls.Add(this.tbCFIgnorePrice);
@@ -508,12 +566,63 @@
this.tabPage3.TabIndex = 1;
this.tabPage3.Text = "Preference";
//
// materialLabel19
//
this.materialLabel19.AutoSize = true;
this.materialLabel19.Depth = 0;
this.materialLabel19.Font = new System.Drawing.Font("Microsoft Sans Serif", 11F);
this.materialLabel19.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(222)))), ((int)(((byte)(0)))), ((int)(((byte)(0)))), ((int)(((byte)(0)))));
this.materialLabel19.Location = new System.Drawing.Point(80, 504);
this.materialLabel19.MouseState = MaterialSkin.MouseState.HOVER;
this.materialLabel19.Name = "materialLabel19";
this.materialLabel19.Size = new System.Drawing.Size(145, 18);
this.materialLabel19.TabIndex = 41;
this.materialLabel19.Text = "초 후 미체결 매수 취소";
//
// tbAutoCancelDelay
//
this.tbAutoCancelDelay.Depth = 0;
this.tbAutoCancelDelay.Hint = "";
this.tbAutoCancelDelay.Location = new System.Drawing.Point(52, 503);
this.tbAutoCancelDelay.MouseState = MaterialSkin.MouseState.HOVER;
this.tbAutoCancelDelay.Name = "tbAutoCancelDelay";
this.tbAutoCancelDelay.PasswordChar = '\0';
this.tbAutoCancelDelay.RightToLeft = System.Windows.Forms.RightToLeft.Yes;
this.tbAutoCancelDelay.SelectedText = "";
this.tbAutoCancelDelay.SelectionLength = 0;
this.tbAutoCancelDelay.SelectionStart = 0;
this.tbAutoCancelDelay.Size = new System.Drawing.Size(24, 23);
this.tbAutoCancelDelay.TabIndex = 40;
this.tbAutoCancelDelay.Text = "30";
this.tbAutoCancelDelay.UseSystemPasswordChar = false;
//
// cbAutoCancel
//
this.cbAutoCancel.AutoSize = true;
this.cbAutoCancel.Depth = 0;
this.cbAutoCancel.Font = new System.Drawing.Font("Microsoft Sans Serif", 10F);
this.cbAutoCancel.Location = new System.Drawing.Point(23, 497);
this.cbAutoCancel.Margin = new System.Windows.Forms.Padding(0);
this.cbAutoCancel.MouseLocation = new System.Drawing.Point(-1, -1);
this.cbAutoCancel.MouseState = MaterialSkin.MouseState.HOVER;
this.cbAutoCancel.Name = "cbAutoCancel";
this.cbAutoCancel.Ripple = true;
this.cbAutoCancel.Size = new System.Drawing.Size(26, 30);
this.cbAutoCancel.TabIndex = 39;
this.cbAutoCancel.UseVisualStyleBackColor = true;
//
// cbMockTrading
//
this.cbMockTrading.AutoSize = true;
this.cbMockTrading.Location = new System.Drawing.Point(29, 519);
this.cbMockTrading.Depth = 0;
this.cbMockTrading.Font = new System.Drawing.Font("Microsoft Sans Serif", 10F);
this.cbMockTrading.Location = new System.Drawing.Point(23, 580);
this.cbMockTrading.Margin = new System.Windows.Forms.Padding(0);
this.cbMockTrading.MouseLocation = new System.Drawing.Point(-1, -1);
this.cbMockTrading.MouseState = MaterialSkin.MouseState.HOVER;
this.cbMockTrading.Name = "cbMockTrading";
this.cbMockTrading.Size = new System.Drawing.Size(76, 16);
this.cbMockTrading.Ripple = true;
this.cbMockTrading.Size = new System.Drawing.Size(94, 30);
this.cbMockTrading.TabIndex = 38;
this.cbMockTrading.Text = "모의 투자";
this.cbMockTrading.UseVisualStyleBackColor = true;
@@ -527,7 +636,7 @@
this.materialLabel18.Location = new System.Drawing.Point(99, 455);
this.materialLabel18.MouseState = MaterialSkin.MouseState.HOVER;
this.materialLabel18.Name = "materialLabel18";
this.materialLabel18.Size = new System.Drawing.Size(114, 18);
this.materialLabel18.Size = new System.Drawing.Size(111, 18);
this.materialLabel18.TabIndex = 37;
this.materialLabel18.Text = "원 이하 체결 무시";
//
@@ -917,7 +1026,7 @@
this.materialLabel3.Name = "materialLabel3";
this.materialLabel3.Size = new System.Drawing.Size(162, 18);
this.materialLabel3.TabIndex = 6;
this.materialLabel3.Text = "Version : 2018.01.04.12";
this.materialLabel3.Text = "Version : 2018.12.26.00";
//
// materialLabel2
//
@@ -1181,26 +1290,6 @@
this.btLoad.UseVisualStyleBackColor = true;
this.btLoad.Click += new System.EventHandler(this.btLoad_Click);
//
// columnHeader6
//
this.columnHeader6.Text = "정산금액";
//
// columnHeader7
//
this.columnHeader7.Text = "수수료";
//
// columnHeader8
//
this.columnHeader8.Text = "거래세";
//
// columnHeader9
//
this.columnHeader9.Text = "농특세";
//
// columnHeader10
//
this.columnHeader10.Text = "날짜";
//
// lvItems
//
this.lvItems.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
@@ -1432,7 +1521,9 @@
private MaterialSkin.Controls.MaterialTabSelector materialTabSelector1;
private MaterialSkin.Controls.MaterialTabControl materialTabControl1;
private System.Windows.Forms.TabPage tabPage1;
private System.Windows.Forms.TabPage tabPage2;
private System.Windows.Forms.TabPage tabPage3;
private System.Windows.Forms.TabPage tabPage4;
private System.Windows.Forms.SplitContainer splitContainer1;
private ListViewNF lvItems;
private System.Windows.Forms.ColumnHeader chCodeName;
@@ -1469,7 +1560,7 @@
private MaterialSkin.Controls.MaterialSingleLineTextField tbTrailingP;
private MaterialSkin.Controls.MaterialLabel materialLabel5;
private MaterialSkin.Controls.MaterialLabel materialLabel4;
private System.Windows.Forms.TabPage tabPage4;
private MaterialSkin.Controls.MaterialFlatButton btLoad;
private MaterialSkin.Controls.MaterialFlatButton btSimulate;
private System.Windows.Forms.RichTextBox tbSimulationLog;
@@ -1516,14 +1607,13 @@
private System.Windows.Forms.ColumnHeader chNCOrgOrderNo;
public MaterialSkin.Controls.MaterialCheckBox chSMHalfTrailing;
private System.Windows.Forms.ColumnHeader chNCOrderNo;
private System.Windows.Forms.CheckBox cbMockTrading;
private MaterialSkin.Controls.MaterialCheckBox cbMockTrading;
private MaterialSkin.Controls.MaterialLabel lbSBCnt;
private MaterialSkin.Controls.MaterialLabel lbRQCnt;
private MaterialSkin.Controls.MaterialLabel lbTRCnt;
private MaterialSkin.Controls.MaterialRaisedButton btClearAll;
private System.Windows.Forms.SplitContainer splitContainer4;
private MaterialSkin.Controls.MaterialRaisedButton btUpdateNC;
private System.Windows.Forms.TabPage tabPage2;
private System.Windows.Forms.ListView lvConclusion;
private System.Windows.Forms.ColumnHeader columnHeader2;
private System.Windows.Forms.ColumnHeader columnHeader3;
@@ -1535,5 +1625,10 @@
private System.Windows.Forms.ColumnHeader columnHeader8;
private System.Windows.Forms.ColumnHeader columnHeader9;
private System.Windows.Forms.ColumnHeader columnHeader10;
private MaterialSkin.Controls.MaterialRaisedButton btClearBeforeClosing;
private MaterialSkin.Controls.MaterialRaisedButton btCancel;
private MaterialSkin.Controls.MaterialLabel materialLabel19;
private MaterialSkin.Controls.MaterialSingleLineTextField tbAutoCancelDelay;
private MaterialSkin.Controls.MaterialCheckBox cbAutoCancel;
}
}

View File

@@ -67,6 +67,7 @@ namespace AutoSellerNS
List<NCITEM> m_NCItems = new List<NCITEM>();
string m_strSelectedCode = "";
bool m_bSell = false;
bool m_bClearBeforeClosing = false;
System.Timers.Timer m_Timer = new System.Timers.Timer();
@@ -75,12 +76,28 @@ namespace AutoSellerNS
InitializeComponent();
cbSMMethod.SelectedIndex = 0;
foreach (TabPage tabPage in materialTabSelector1.BaseTabControl.TabPages)
{
var currentTabIndex = materialTabSelector1.BaseTabControl.TabPages.IndexOf(tabPage);
Console.WriteLine($"{tabPage.Text} : {currentTabIndex}");
}
for(int i=0; i< materialTabSelector1.BaseTabControl.TabPages.Count; i++)
{
var tabPage = materialTabSelector1.BaseTabControl.TabPages[i];
var currentTabIndex = materialTabSelector1.BaseTabControl.TabPages.IndexOf(tabPage);
Console.WriteLine($"{tabPage.Text}: {currentTabIndex}");
//new Rectangle(MaterialSkinManager.Instance.FORM_PADDING,
}
Util.SetLogView(tbLog);
Config.Init();
btUpdate.Enabled = false;
btSell.Enabled = false;
for (int i = 0; i < 21; i++)
{
lvCurPrice.Items.Add(new ListViewItem(new string[] { "", "", "", "" }));
@@ -116,6 +133,9 @@ namespace AutoSellerNS
tbCFTimeDown.Text = Config.GetTimeDown().ToString();
tbCFIgnorePrice.Text = Config.GetIgnorePrice().ToString();
cbAutoCancel.Checked = Config.IsAutoCancel();
tbAutoCancelDelay.Text = Config.GetAutoCancelDelay().ToString();
cbMockTrading.Checked = Config.GetMockTrading();
m_CybosHelper = new CybosHelper(this);
@@ -247,6 +267,27 @@ namespace AutoSellerNS
m_CybosHelper.UpdateItems();
}
public void UpdateItem(bool bBid, string strCodeName, string strCode, int iPrice, int iConclusionCnt)
{
lock (m_Items)
{
int iIdx = m_Items.FindIndex(s => s.m_strCode == strCode);
if (iIdx < 0)
{
UpdateItem();
return;
}
ITEM Item = m_Items[iIdx];
Item.m_iItemCnt += bBid ? iConclusionCnt : -iConclusionCnt;
if (Item.m_iItemCnt == 0)
m_Items.RemoveAt(iIdx);
SyncListViewItems(m_Items);
}
}
public void UpdateItemCallback(List<ITEM> Items)
{
SyncItems(m_Items, Items);
@@ -305,6 +346,26 @@ namespace AutoSellerNS
m_CybosHelper.UpdateNC();
}
public void UpdateNCItem(bool bConclusion, bool bBid, string strCodeName, string strCode, int iPrice, int iConclusionCnt)
{
lock (m_NCItems)
{
int iIdx = m_NCItems.FindIndex(s => s.m_strCode == strCode);
if (iIdx < 0)
{
UpdateNCItem();
return;
}
NCITEM Item = m_NCItems[iIdx];
Item.m_iRemainCnt += (bConclusion ? -iConclusionCnt : iConclusionCnt);
if (Item.m_iRemainCnt == 0)
m_NCItems.RemoveAt(iIdx);
SyncNCListVIewItems(m_NCItems);
}
}
public void UpdateNCItemCallback(List<AutoSeller.NCITEM> NCItems)
{
SyncNCItems(m_NCItems, NCItems);
@@ -339,6 +400,35 @@ namespace AutoSellerNS
}
}
private async void ClearBeforeClsosingProc()
{
if(DateTime.Now >= m_CybosHelper.GetMarketEndTime()-TimeSpan.FromMinutes(10))
{
// 미체결 모두 취소
foreach (var ncitem in m_NCItems)
await m_CybosHelper.CancelItem(ncitem.m_strCode, ncitem.m_iOrgOrderNo);
// 잔량 모두 시장가로 매도
foreach (var item in m_Items)
await m_CybosHelper.SellItem(item.m_strCode, item.m_iAvailableQuantity);
}
}
private async void AutoCancelProc()
{
TimeSpan delay = TimeSpan.FromSeconds(Config.GetAutoCancelDelay());
List<NCITEM> cloned;
lock (m_NCItems)
cloned = m_NCItems.ConvertAll(s => s);
foreach (var nc in cloned)
{
if (nc.m_bAsk == false && DateTime.Now >= nc.m_Time + delay)
await m_CybosHelper.CancelItem(nc.m_strCode, nc.m_iOrgOrderNo);
}
}
private async void Timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
await CorrectItems();
@@ -352,6 +442,12 @@ namespace AutoSellerNS
lbSBCnt.Invoke(new Action(delegate {
lbSBCnt.Text = $"{m_CybosHelper.GetLimitRemainCountSB(), 3}";
}));
if(m_bClearBeforeClosing == true)
ClearBeforeClsosingProc();
if (Config.IsAutoCancel() == true)
AutoCancelProc();
}
private void btUpdate_Click(object sender, EventArgs e)
@@ -455,6 +551,40 @@ namespace AutoSellerNS
return m_bSell;
}
private void btClearBeforeClosing_Click(object sender, EventArgs e)
{
btClearBeforeClosing.Primary = !btClearBeforeClosing.Primary;
m_bClearBeforeClosing = (btClearBeforeClosing.Primary == false);
}
private async void btClearAll_Click(object sender, EventArgs e)
{
List<ITEM> cloned;
lock (m_Items)
cloned = m_Items.ConvertAll(s => s);
foreach (var item in cloned)
{
await m_CybosHelper.SellItem(item.m_strCode, item.m_iItemCnt);
}
}
private void btUpdateNC_Click(object sender, EventArgs e)
{
UpdateNCItem();
}
private async void btCancel_Click(object sender, EventArgs e)
{
foreach(ListViewItem nc in lvNCItem.SelectedItems)
{
string strCode = nc.SubItems[chNCCode.Index].Text;
string strOrgOrderNo = nc.SubItems[chNCOrgOrderNo.Index].Text;
int iOrgOrderNo = int.Parse(strOrgOrderNo);
await m_CybosHelper.CancelItem(strCode, iOrgOrderNo);
}
}
public void OnReceivedCurPrice(string strCode, int iPrice, int iMaxPrice, double dCheckCountLimit, int iCheckCount, bool bReal)
{
ITEM Item = m_Items.FirstOrDefault(s => s.m_strCode == strCode);
@@ -588,6 +718,11 @@ namespace AutoSellerNS
int.TryParse(tbCFIgnorePrice.Text, out iIgnorePrice);
Config.SetVolatility(iListSize, dFastSD, dFastUp, dFastDown, dSlowSD, dSlowUp, dSlowDown, iTimeLimit, dTimeDown, iIgnorePrice);
int iAutoCancelDelay;
int.TryParse(tbAutoCancelDelay.Text, out iAutoCancelDelay);
Config.SetAutoCancel(cbAutoCancel.Checked, iAutoCancelDelay);
Config.SetMockTrading(cbMockTrading.Checked);
}
@@ -639,11 +774,6 @@ namespace AutoSellerNS
SimulationHelper helper = new SimulationHelper(this, m_CybosHelper, tbSimulationLog);
helper.StartSimuation2();
}
private void btUpdateNC_Click(object sender, EventArgs e)
{
UpdateNCItem();
}
#endregion
private void lvItems_ColumnClick(object sender, ColumnClickEventArgs e)
@@ -664,17 +794,6 @@ namespace AutoSellerNS
lvNCItem.Sort();
}
private async void btClearAll_Click(object sender, EventArgs e)
{
List<ITEM> cloned;
lock (m_Items)
cloned = m_Items.ConvertAll(s => s);
foreach(var item in cloned)
{
await m_CybosHelper.SellItem(item.m_strCode, item.m_iItemCnt);
}
}
private void btUpdateConclusion_Click(object sender, EventArgs e)
{
m_CybosHelper.GetConclusion();
@@ -718,5 +837,10 @@ namespace AutoSellerNS
lvConclusion.EndUpdate();
}));
}
public void ErrorCallback(string msg)
{
Util.Log(Util.LOG_TYPE.ERROR, msg);
}
}
}

View File

@@ -94,6 +94,7 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="ConcurrentList.cs" />
<Compile Include="Config.cs" />
<Compile Include="CurrentItem.cs" />
<Compile Include="CybosHelper.cs" />

104
ConcurrentList.cs Normal file
View File

@@ -0,0 +1,104 @@
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AutoSellerNS
{
public class ConcurrentList<T> : ConcurrentDictionary<int, T>, IList<T>
{
int m_Order = 0;
public new T this[int index]
{
get
{
T value;
if (ContainsKey(index) == true)
{
TryGetValue(index, out value);
return value;
}
else
{
throw new IndexOutOfRangeException();
}
}
set
{
AddOrUpdate(index, value, (k, v) => value);
}
}
public bool IsReadOnly
{
get
{
return false;
}
}
public void Add(T item)
{
TryAdd(m_Order++, item);
}
public bool Contains(T item)
{
return Contains(item);
}
public void CopyTo(T[] array, int arrayIndex)
{
throw new NotImplementedException();
}
public int IndexOf(T item)
{
foreach(var kv in this)
{
if (kv.Value.Equals(item))
return kv.Key;
}
return -1;
}
public void Insert(int index, T item)
{
if(index < 0 || index >= m_Order)
throw new ArgumentOutOfRangeException();
this[index] = item;
}
public bool Remove(T item)
{
int index = IndexOf(item);
if (index < 0)
return false;
this[index] = default(T);
return true;
}
public void RemoveAt(int index)
{
if (index < 0 || ContainsKey(index) == false)
throw new ArgumentOutOfRangeException();
this[index] = default(T);
}
IEnumerator<T> IEnumerable<T>.GetEnumerator()
{
foreach(var kv in this)
{
yield return kv.Value;
}
}
}
}

View File

@@ -33,6 +33,8 @@ namespace AutoSellerNS
m_Data.Add("time-down", 0.02);
m_Data.Add("ignore-price", 50000);
m_Data.Add("mock-trading", false);
m_Data.Add("auto-cancel", false);
m_Data.Add("auto-cancel-delay", 30);
Load();
}
@@ -145,6 +147,13 @@ namespace AutoSellerNS
public static int GetTimeLimit() { return (int)m_Data["time-limit"]; }
public static double GetTimeDown() { return (double)m_Data["time-down"]; }
public static int GetIgnorePrice() { return (int)m_Data["ignore-price"]; }
public static void SetAutoCancel(bool bCancel, int iDelay)
{
m_Data["auto-cancel"] = bCancel;
m_Data["auto-cancel-delay"] = iDelay;
}
public static bool IsAutoCancel() { return (bool)m_Data["auto-cancel"]; }
public static int GetAutoCancelDelay() { return (int)m_Data["auto-cancel-delay"]; }
public static void SetMockTrading(bool bMockTrading) { m_Data["mock-trading"] = bMockTrading; Save(); }
public static bool GetMockTrading() { return (bool)m_Data["mock-trading"]; }

View File

@@ -121,7 +121,7 @@ namespace AutoSellerNS
if (m_iCheckCount >= m_dCheckCountLimit && m_Listener.IsSelling() == true)
{
await m_CybosHelper.SellItem(m_strCode, m_Listener.GetSellableCount(m_strCode), m_aiAskPrice[0]);
await m_CybosHelper.SellItem(m_strCode, m_Listener.GetSellableCount(m_strCode), m_aiAskPrice[0]-m_CybosHelper.GetUnitValue(m_iCurPrice));
Util.Log(Util.LOG_TYPE.SELL, string.Format("[조건 완료 매도] {0} ({1}회) (현재가 {2:n0}원, 최고가 {3:n0}원)",
m_strCodeName,
Config.GetBidCount(),
@@ -133,7 +133,7 @@ namespace AutoSellerNS
m_iTrailingCount++;
if (m_iTrailingCount >= Config.GetTrailingCnt() && m_Listener.IsSelling() == true)
{
await m_CybosHelper.SellItem(m_strCode, m_Listener.GetSellableCount(m_strCode), m_aiAskPrice[0]);
await m_CybosHelper.SellItem(m_strCode, m_Listener.GetSellableCount(m_strCode), m_aiAskPrice[0]-m_CybosHelper.GetUnitValue(m_iCurPrice));
Util.Log(Util.LOG_TYPE.SELL, string.Format("[트레일링 매도] {0} ({1}% {2}회) (현재가 {3:n0}원, 최고가 {4:n0}원)",
m_strCodeName,
Config.GetTrailingRate(),
@@ -144,7 +144,7 @@ namespace AutoSellerNS
if (iTimeDiff >= Config.GetTimeLimit() && m_Listener.IsSelling() == true)
{
await m_CybosHelper.SellItem(m_strCode, m_Listener.GetSellableCount(m_strCode), m_aiAskPrice[0]);
await m_CybosHelper.SellItem(m_strCode, m_Listener.GetSellableCount(m_strCode), m_aiAskPrice[0]-m_CybosHelper.GetUnitValue(m_iCurPrice));
Util.Log(Util.LOG_TYPE.SELL, string.Format("[시간제한 매도] {0} ({1}초) (현재가 {2:n0}원, 최고가 {3:n0}원)",
m_strCodeName,
iTimeDiff,

View File

@@ -14,6 +14,7 @@ namespace AutoSellerNS
AutoSeller m_Listener = null;
CPUTILLib.CpCybos m_CPCybos = new CPUTILLib.CpCybos();
CPUTILLib.CpCodeMgr m_CPCodeMgr = new CPUTILLib.CpCodeMgr();
CPFORETRADELib.CpForeTdUtil m_CPUtil = new CPFORETRADELib.CpForeTdUtil();
DSCBO1Lib.CpConclusion m_CpConclusion = new DSCBO1Lib.CpConclusion();
@@ -28,6 +29,10 @@ namespace AutoSellerNS
ConcurrentDictionary<string, int> m_SellingCode = new ConcurrentDictionary<string, int>();
ConcurrentDictionary<int, string> m_ItemsInCorrection = new ConcurrentDictionary<int, string>();
ConcurrentQueue<CPTRADELib.ICpTdDib> m_TRQueue = new ConcurrentQueue<CPTRADELib.ICpTdDib>();
DateTime m_MarketStartTime;
DateTime m_MarketEndTime;
public CybosHelper(AutoSeller Listener)
{
@@ -65,7 +70,14 @@ namespace AutoSellerNS
m_Listener.SetAccountList(m_CPUtil.AccountNumber);
m_CpConclusion.Received += CpConclusion_Received;
m_CpConclusion.Subscribe();
}
int iStartTime = (int)m_CPCodeMgr.GetMarketStartTime();
int iEndTime = (int)m_CPCodeMgr.GetMarketEndTime();
m_MarketStartTime = DateTime.Parse(string.Format("{0:00}:{1:00}:{2:00}", iStartTime/100, iStartTime%100, 0));
m_MarketEndTime = DateTime.Parse(string.Format("{0:00}:{1:00}:{2:00}", iEndTime / 100, iEndTime % 100, 0));
}
public async Task InitCybosAsync()
{
@@ -118,23 +130,32 @@ namespace AutoSellerNS
}
}
int iTdDibWaitCnt = 0;
ConcurrentQueue<CPTRADELib.ICpTdDib> m_TRQueue = new ConcurrentQueue<CPTRADELib.ICpTdDib>();
void BlockRequestTRProc()
{
if (m_TRQueue.Count == 0)
return;
lock (m_RequestTRLock)
{
CPTRADELib.ICpTdDib tr;
bool bContinue = true;
while (bContinue == true && m_TRQueue.TryDequeue(out tr) == true && GetLimitRemainCountTrade() > 0)
{
var ret = tr.BlockRequest2(0);
if (ret == -1)
Util.Log(Util.LOG_TYPE.DEBUG, "BlockRequest TR 오류");
else if (ret == 1)
Util.Log(Util.LOG_TYPE.DEBUG, "BlockRequest TR 수신대기");
bContinue = (ret == 0);
}
}
}
//int iTdDibWaitCnt = 0;
void BlockRequest(CPTRADELib.ICpTdDib dib)
{
m_TRQueue.Enqueue(dib);
CPTRADELib.ICpTdDib tr;
bool bContinue = true;
while(bContinue == true && m_TRQueue.TryDequeue(out tr) == true)
{
var ret = tr.BlockRequest2(0);
if (ret == -1)
Util.Log(Util.LOG_TYPE.DEBUG, "BlockRequest TR 오류");
else if (ret == 1)
Util.Log(Util.LOG_TYPE.DEBUG, "BlockRequest TR 수신대기");
bContinue = (ret == 0);
}
BlockRequestTRProc();
////lock (m_RequestTRLock)
//{
@@ -153,22 +174,25 @@ namespace AutoSellerNS
//}
}
public void UpdateItems()
{
if (Config.GetAccount() == "")
return;
m_CP6033.SetInputValue(0, Config.GetAccount());
m_CP6033.SetInputValue(1, Config.GetSubAccount());
m_CP6033.SetInputValue(2, 50);
string Msg1 = m_CP6033.GetDibMsg1();
string Msg2 = m_CP6033.GetDibMsg2();
int iStatus = m_CP6033.GetDibStatus();
if (iStatus == 1)
return;
if (iStatus == -1)
m_Listener.ErrorCallback($"Update Item Error\nStatus: {iStatus}\nMsg1: {Msg1}\nMsg2: {Msg2}");
m_CP6033.SetInputValue(0, Config.GetAccount());
m_CP6033.SetInputValue(1, Config.GetSubAccount());
m_CP6033.SetInputValue(2, 50);
m_CP6033.Request();
}
@@ -254,8 +278,8 @@ namespace AutoSellerNS
public void UpdateNC()
{
m_CP5339.SetInputValue(0, Config.GetAccount());
m_CP5339.SetInputValue(1, Config.GetSubAccount());
if (Config.GetAccount() == "")
return;
string Msg1 = m_CP5339.GetDibMsg1();
string Msg2 = m_CP5339.GetDibMsg2();
@@ -263,6 +287,11 @@ namespace AutoSellerNS
if (iStatus == 1)
return;
if (iStatus == -1)
m_Listener.ErrorCallback($"UpdateNC Item Error\nStatus: {iStatus}\nMsg1: {Msg1}\nMsg2: {Msg2}");
m_CP5339.SetInputValue(0, Config.GetAccount());
m_CP5339.SetInputValue(1, Config.GetSubAccount());
m_CP5339.Request();
}
@@ -313,12 +342,19 @@ namespace AutoSellerNS
int iPrice = m_CpConclusion.GetHeaderValue(4);
int iOrderNumber = m_CpConclusion.GetHeaderValue(5);
int iOrgOrderNumber = m_CpConclusion.GetHeaderValue(6);
string strCancel = m_CpConclusion.GetHeaderValue(16);
string strOrderType = m_CpConclusion.GetHeaderValue(16);
string strOrderCondition = m_CpConclusion.GetHeaderValue(19);
int iBookValue = m_CpConclusion.GetHeaderValue(21);
int iRemainCnt = m_CpConclusion.GetHeaderValue(23);
string strBidOrAsk = bBid ? "매수" : "매도";
if (strOrderType == "1")
strOrderType = "정상 주문";
else if (strOrderType == "2")
strOrderType = "정정 주문";
else if (strOrderType == "3")
strOrderType = "취소 주문";
if (strOrderCondition == "0")
strOrderCondition = "없음";
else if (strOrderCondition == "1")
@@ -329,22 +365,29 @@ namespace AutoSellerNS
switch (iType)
{
case 1: // 체결
m_Listener.UpdateItem();
m_Listener.UpdateItem(bBid, strCodeName, strCode, iPrice, iConclusionCnt);
m_Listener.UpdateNCItem();
Util.Log(bBid?Util.LOG_TYPE.BUY_CONCLUSION:Util.LOG_TYPE.SELL_CONCLUSION, string.Format("{0}:{1} {2} 체결 ({3:n0}원 {4}주) - {5}", strCodeName, strCode, strBidOrAsk, iPrice, iConclusionCnt, strOrderCondition));
//if (strOrderType == "정상 주문")
// m_Listener.UpdateNCItem(true, bBid, strCodeName, strCode, iPrice, iConclusionCnt);
Util.Log(bBid?Util.LOG_TYPE.BUY_CONCLUSION:Util.LOG_TYPE.SELL_CONCLUSION, string.Format("{0}:{1} {2} {3} 체결 ({4:n0}원 {5}주) - {6}",
strCodeName, strCode, strBidOrAsk, strOrderType, iPrice, iConclusionCnt, strOrderCondition));
break;
case 2: // 확인
Util.Log(Util.LOG_TYPE.VERBOSE, string.Format("{0}:{1} {2} 확인 - {3} ({4}:{5})", strCodeName, strCode, strBidOrAsk, strOrderCondition, iOrderNumber, iOrgOrderNumber));
Util.Log(Util.LOG_TYPE.VERBOSE, string.Format("{0}:{1} {2} {3} 확인 - {4} ({5}:{6})",
strCodeName, strCode, strBidOrAsk, strOrderType, strOrderCondition, iOrderNumber, iOrgOrderNumber));
break;
case 3: // 거부
Util.Log(Util.LOG_TYPE.VERBOSE, string.Format("{0}:{1} {2} 거부", strCodeName, strCode, strBidOrAsk));
Util.Log(Util.LOG_TYPE.VERBOSE, string.Format("{0}:{1} {2} {3} 거부", strCodeName, strCode, strBidOrAsk, strOrderType));
break;
case 4: // 접수
m_Listener.UpdateNCItem();
Util.Log(bBid ? Util.LOG_TYPE.BUY : Util.LOG_TYPE.SELL, string.Format("{0}:{1} {2} 접수 ({3:n0}원 {4}주) - {5}", strCodeName, strCode, strBidOrAsk, iPrice, iConclusionCnt, strOrderCondition));
//if(strOrderType == "정상 주문")
// m_Listener.UpdateNCItem(false, bBid, strCodeName, strCode, iPrice, iConclusionCnt);
Util.Log(bBid ? Util.LOG_TYPE.BUY : Util.LOG_TYPE.SELL, string.Format("{0}:{1} {2} {3} 접수 ({4:n0}원 {5}주) - {6}",
strCodeName, strCode, strBidOrAsk, strOrderType, iPrice, iConclusionCnt, strOrderCondition));
if (bBid == false)
{
if(m_aStockCur.ContainsKey(strCode) == true)
@@ -458,6 +501,16 @@ namespace AutoSellerNS
return (iValue/iUnit)*iUnit;
}
public DateTime GetMarketStartTime()
{
return m_MarketStartTime;
}
public DateTime GetMarketEndTime()
{
return m_MarketEndTime;
}
public async Task SellItem(string strCode, int iCnt, int iAskPrice)
{
if (iCnt <= 0 || m_SellingCode.ContainsKey(strCode) == true)
@@ -467,7 +520,7 @@ namespace AutoSellerNS
await Task.Run(() =>
{
int iSellPrice = iAskPrice - GetUnitValue(iAskPrice);
int iSellPrice = iAskPrice;
CPTRADELib.CpTd0311 Td0311 = new CPTRADELib.CpTd0311();
Td0311.SetInputValue(0, "1");
@@ -486,9 +539,11 @@ namespace AutoSellerNS
public async Task SellItem(string strCode, int iCnt)
{
if (iCnt <= 0)
if (iCnt <= 0 || m_SellingCode.ContainsKey(strCode) == true)
return;
m_SellingCode.TryAdd(strCode, 0);
await Task.Run(() =>
{
CPTRADELib.CpTd0311 Td0311 = new CPTRADELib.CpTd0311();
@@ -499,6 +554,9 @@ namespace AutoSellerNS
Td0311.SetInputValue(4, iCnt);
Td0311.SetInputValue(8, "03");
BlockRequest(Td0311);
int val;
m_SellingCode.TryRemove(strCode, out val);
});
}
@@ -527,8 +585,9 @@ namespace AutoSellerNS
{
await Task.Run(() =>
{
CancelItem(strCode, iOrgOrderNo).Wait();
SellItem(strCode, iCnt, iAskPrice).Wait();
var a = CancelItem(strCode, iOrgOrderNo);
Thread.Sleep(2000);
a = SellItem(strCode, iCnt, iAskPrice);
string strCode2;
m_ItemsInCorrection.TryRemove(iOrgOrderNo, out strCode2);

View File

@@ -33,7 +33,7 @@ namespace AutoSellerNS
StockBid CPStockBid = new StockBid();
ExcelHandler Excel = null;
foreach(string strLine in File.ReadLines(Util.GetSimulationPath()+"/0-input.txt", Encoding.UTF8))
foreach(string strLine in File.ReadLines(GetInputFileName(), Encoding.UTF8))
{
var tokens = strLine.Split('\t');
@@ -210,6 +210,10 @@ namespace AutoSellerNS
var tokens = strLine.Split('\t');
if (tokens == null || tokens.Length <= 4)
return new object[] { "input error \n", 0 };
var strDate = tokens[0];
var strSimulationTime = tokens[1];
var strCodeName = tokens[2];
@@ -312,30 +316,20 @@ namespace AutoSellerNS
if(bStart == false)
{
if(RowDT >= StartDT && iPrice==iStartPrice)
bStart = true;
iStartRow = iRow;
iMaxPriceRow = iRow;
iMaxPrice = iStartPrice;
for(int i = 1; i<=iFillColumns; i++)
{
bStart = true;
iStartRow = iRow;
iMaxPriceRow = iRow;
iMaxPrice = iStartPrice;
for(int i = 1; i<=iFillColumns; i++)
{
Sheet.Cells[iRow, i].Style.Fill.PatternType = OfficeOpenXml.Style.ExcelFillStyle.Solid;
Sheet.Cells[iRow, i].Style.Fill.BackgroundColor.SetColor(BidBackColor);
}
m_PriceList.Clear();
m_PriceList.Add(iPrice);
}
else if((RowDT-StartDT).Minutes > 10)
{
InsertLog(string.Format("[{0}] [{1}] 매수 가격 찾기 실패\n",
StartDT.ToString("yyyy-MM-dd"),
strCodeName));
break;
Sheet.Cells[iRow, i].Style.Fill.PatternType = OfficeOpenXml.Style.ExcelFillStyle.Solid;
Sheet.Cells[iRow, i].Style.Fill.BackgroundColor.SetColor(BidBackColor);
}
m_PriceList.Clear();
m_PriceList.Add(iPrice);
}
else
{
@@ -684,7 +678,7 @@ namespace AutoSellerNS
List<string> aLines = new List<string>();
List<Task<object>> aTasks = new List<Task<object>>();
foreach(string strLine in File.ReadLines(Util.GetSimulationPath()+"/0-input.txt", Encoding.UTF8))
foreach(string strLine in File.ReadLines(GetInputFileName(), Encoding.UTF8))
{
var task = Task.Factory.StartNew<object>(() =>
SimulationWork(new object[] {
@@ -775,6 +769,16 @@ namespace AutoSellerNS
});
}
string GetInputFileName()
{
string strPath = Util.GetSimulationPath() + "/0-input-" + DateTime.Now.Date.ToString("yyyy-MM-dd") + ".txt";
if (File.Exists(strPath) == true)
return strPath;
strPath = Util.GetSimulationPath() + "/0-input.txt";
return strPath;
}
public static void InsertSimulationLog(string strCode, string strCodeName, List<Tuple<int, int>> PriceDealCntList)
{
DateTime time = DateTime.Now;