Compare commits
3 Commits
0a3bc6b77d
...
9493b9f4d5
| Author | SHA1 | Date | |
|---|---|---|---|
| 9493b9f4d5 | |||
| 22b38609cd | |||
| 7197272479 |
674
AutoSeller.Designer.cs
generated
674
AutoSeller.Designer.cs
generated
File diff suppressed because it is too large
Load Diff
157
AutoSeller.cs
157
AutoSeller.cs
@@ -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,6 +76,23 @@ namespace AutoSellerNS
|
||||
InitializeComponent();
|
||||
cbSMMethod.SelectedIndex = 0;
|
||||
|
||||
foreach (TabPage tabPage in materialTabSelector1.BaseTabControl.TabPages)
|
||||
{
|
||||
Console.WriteLine(tabPage.Text);
|
||||
var currentTabIndex = materialTabSelector1.BaseTabControl.TabPages.IndexOf(tabPage);
|
||||
Console.WriteLine(currentTabIndex);
|
||||
}
|
||||
|
||||
for(int i=0; i< materialTabSelector1.BaseTabControl.TabPages.Count; i++)
|
||||
{
|
||||
var tabPage = materialTabSelector1.BaseTabControl.TabPages[i];
|
||||
Console.WriteLine(tabPage.Text);
|
||||
var currentTabIndex = materialTabSelector1.BaseTabControl.TabPages.IndexOf(tabPage);
|
||||
Console.WriteLine(currentTabIndex);
|
||||
|
||||
//new Rectangle(MaterialSkinManager.Instance.FORM_PADDING,
|
||||
}
|
||||
|
||||
Util.SetLogView(tbLog);
|
||||
Config.Init();
|
||||
|
||||
@@ -116,6 +134,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 +268,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 +347,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 +401,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 +443,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 +552,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 +719,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 +775,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 +795,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 +838,10 @@ namespace AutoSellerNS
|
||||
lvConclusion.EndUpdate();
|
||||
}));
|
||||
}
|
||||
|
||||
public void ErrorCallback(string msg)
|
||||
{
|
||||
Util.Log(Util.LOG_TYPE.ERROR, msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
104
ConcurrentList.cs
Normal 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 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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"]; }
|
||||
|
||||
|
||||
@@ -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,
|
||||
|
||||
101
CybosHelper.cs
101
CybosHelper.cs
@@ -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,6 +70,13 @@ 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,15 +130,16 @@ namespace AutoSellerNS
|
||||
}
|
||||
}
|
||||
|
||||
int iTdDibWaitCnt = 0;
|
||||
ConcurrentQueue<CPTRADELib.ICpTdDib> m_TRQueue = new ConcurrentQueue<CPTRADELib.ICpTdDib>();
|
||||
void BlockRequest(CPTRADELib.ICpTdDib dib)
|
||||
void BlockRequestTRProc()
|
||||
{
|
||||
m_TRQueue.Enqueue(dib);
|
||||
if (m_TRQueue.Count == 0)
|
||||
return;
|
||||
|
||||
lock (m_RequestTRLock)
|
||||
{
|
||||
CPTRADELib.ICpTdDib tr;
|
||||
bool bContinue = true;
|
||||
while(bContinue == true && m_TRQueue.TryDequeue(out tr) == true)
|
||||
while (bContinue == true && m_TRQueue.TryDequeue(out tr) == true && GetLimitRemainCountTrade() > 0)
|
||||
{
|
||||
var ret = tr.BlockRequest2(0);
|
||||
if (ret == -1)
|
||||
@@ -135,6 +148,14 @@ namespace AutoSellerNS
|
||||
Util.Log(Util.LOG_TYPE.DEBUG, "BlockRequest TR 수신대기");
|
||||
bContinue = (ret == 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
//int iTdDibWaitCnt = 0;
|
||||
void BlockRequest(CPTRADELib.ICpTdDib dib)
|
||||
{
|
||||
m_TRQueue.Enqueue(dib);
|
||||
|
||||
BlockRequestTRProc();
|
||||
|
||||
////lock (m_RequestTRLock)
|
||||
//{
|
||||
@@ -159,16 +180,19 @@ namespace AutoSellerNS
|
||||
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);
|
||||
|
||||
@@ -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];
|
||||
@@ -311,8 +315,6 @@ namespace AutoSellerNS
|
||||
iStockCount = 1000000/iStartPrice;
|
||||
|
||||
if(bStart == false)
|
||||
{
|
||||
if(RowDT >= StartDT && iPrice==iStartPrice)
|
||||
{
|
||||
bStart = true;
|
||||
iStartRow = iRow;
|
||||
@@ -329,14 +331,6 @@ namespace AutoSellerNS
|
||||
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;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
m_PriceList.Add(iPrice);
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user