async하게 수정

This commit is contained in:
2018-06-07 15:33:33 +09:00
parent 663d2977ed
commit 9140673315
11 changed files with 412 additions and 317 deletions

1
.gitignore vendored
View File

@@ -6,3 +6,4 @@ log/
publish/ publish/
*.user *.user
simulation/ simulation/
packages/

23
AutoSeller.Designer.cs generated
View File

@@ -50,6 +50,7 @@
this.chCheckCountLimit = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); this.chCheckCountLimit = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.chCheckCount = ((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.lvNCItem = new AutoSellerNS.ListViewNF();
this.chNCOrderNo = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.chNCOrgOrderNo = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); this.chNCOrgOrderNo = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.chNCCode = ((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.chNCCodeName = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
@@ -65,6 +66,7 @@
this.btUpdate = new MaterialSkin.Controls.MaterialRaisedButton(); this.btUpdate = new MaterialSkin.Controls.MaterialRaisedButton();
this.btCybos = new MaterialSkin.Controls.MaterialRaisedButton(); this.btCybos = new MaterialSkin.Controls.MaterialRaisedButton();
this.tabPage2 = new System.Windows.Forms.TabPage(); this.tabPage2 = new System.Windows.Forms.TabPage();
this.cbMockTrading = new System.Windows.Forms.CheckBox();
this.materialLabel18 = new MaterialSkin.Controls.MaterialLabel(); this.materialLabel18 = new MaterialSkin.Controls.MaterialLabel();
this.tbCFIgnorePrice = new MaterialSkin.Controls.MaterialSingleLineTextField(); this.tbCFIgnorePrice = new MaterialSkin.Controls.MaterialSingleLineTextField();
this.materialLabel17 = new MaterialSkin.Controls.MaterialLabel(); this.materialLabel17 = new MaterialSkin.Controls.MaterialLabel();
@@ -332,6 +334,7 @@
// chCheckCountLimit // chCheckCountLimit
// //
this.chCheckCountLimit.Text = "조건제한"; this.chCheckCountLimit.Text = "조건제한";
this.chCheckCountLimit.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
// //
// chCheckCount // chCheckCount
// //
@@ -341,6 +344,7 @@
// lvNCItem // lvNCItem
// //
this.lvNCItem.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] { this.lvNCItem.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
this.chNCOrderNo,
this.chNCOrgOrderNo, this.chNCOrgOrderNo,
this.chNCCode, this.chNCCode,
this.chNCCodeName, this.chNCCodeName,
@@ -357,6 +361,10 @@
this.lvNCItem.UseCompatibleStateImageBehavior = false; this.lvNCItem.UseCompatibleStateImageBehavior = false;
this.lvNCItem.View = System.Windows.Forms.View.Details; this.lvNCItem.View = System.Windows.Forms.View.Details;
// //
// chNCOrderNo
//
this.chNCOrderNo.Text = "주문번호";
//
// chNCOrgOrderNo // chNCOrgOrderNo
// //
this.chNCOrgOrderNo.Text = "원주문번호"; this.chNCOrgOrderNo.Text = "원주문번호";
@@ -467,6 +475,7 @@
// tabPage2 // tabPage2
// //
this.tabPage2.BackColor = System.Drawing.Color.White; this.tabPage2.BackColor = System.Drawing.Color.White;
this.tabPage2.Controls.Add(this.cbMockTrading);
this.tabPage2.Controls.Add(this.materialLabel18); this.tabPage2.Controls.Add(this.materialLabel18);
this.tabPage2.Controls.Add(this.tbCFIgnorePrice); this.tabPage2.Controls.Add(this.tbCFIgnorePrice);
this.tabPage2.Controls.Add(this.materialLabel17); this.tabPage2.Controls.Add(this.materialLabel17);
@@ -508,6 +517,16 @@
this.tabPage2.TabIndex = 1; this.tabPage2.TabIndex = 1;
this.tabPage2.Text = "Preference"; this.tabPage2.Text = "Preference";
// //
// cbMockTrading
//
this.cbMockTrading.AutoSize = true;
this.cbMockTrading.Location = new System.Drawing.Point(29, 519);
this.cbMockTrading.Name = "cbMockTrading";
this.cbMockTrading.Size = new System.Drawing.Size(76, 16);
this.cbMockTrading.TabIndex = 38;
this.cbMockTrading.Text = "모의 투자";
this.cbMockTrading.UseVisualStyleBackColor = true;
//
// materialLabel18 // materialLabel18
// //
this.materialLabel18.AutoSize = true; this.materialLabel18.AutoSize = true;
@@ -907,7 +926,7 @@
this.materialLabel3.Name = "materialLabel3"; this.materialLabel3.Name = "materialLabel3";
this.materialLabel3.Size = new System.Drawing.Size(165, 19); this.materialLabel3.Size = new System.Drawing.Size(165, 19);
this.materialLabel3.TabIndex = 6; this.materialLabel3.TabIndex = 6;
this.materialLabel3.Text = "Version : 2018.01.01.20"; this.materialLabel3.Text = "Version : 2018.01.04.12";
// //
// materialLabel2 // materialLabel2
// //
@@ -1291,5 +1310,7 @@
public System.Windows.Forms.TextBox tbSMIgnorePrice; public System.Windows.Forms.TextBox tbSMIgnorePrice;
private System.Windows.Forms.ColumnHeader chNCOrgOrderNo; private System.Windows.Forms.ColumnHeader chNCOrgOrderNo;
public MaterialSkin.Controls.MaterialCheckBox chSMHalfTrailing; public MaterialSkin.Controls.MaterialCheckBox chSMHalfTrailing;
private System.Windows.Forms.ColumnHeader chNCOrderNo;
private System.Windows.Forms.CheckBox cbMockTrading;
} }
} }

View File

@@ -1,13 +1,18 @@
using MaterialSkin; using MaterialSkin;
using MaterialSkin.Controls; using MaterialSkin.Controls;
using Newtonsoft.Json.Linq;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel; using System.ComponentModel;
using System.Data; using System.Data;
using System.Drawing; using System.Drawing;
using System.IO;
using System.Linq; using System.Linq;
using System.Net;
using System.Net.Http;
using System.Net.NetworkInformation; using System.Net.NetworkInformation;
using System.Text; using System.Text;
using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows.Forms; using System.Windows.Forms;
@@ -51,6 +56,8 @@ namespace AutoSellerNS
string m_strSelectedCode = ""; string m_strSelectedCode = "";
bool m_bSell = false; bool m_bSell = false;
SemaphoreSlim m_UpdateSemaphore = new SemaphoreSlim(1, 1);
SemaphoreSlim m_NCUpdateSemaphore = new SemaphoreSlim(1, 1);
System.Timers.Timer m_Timer = new System.Timers.Timer(); System.Timers.Timer m_Timer = new System.Timers.Timer();
public AutoSeller() public AutoSeller()
@@ -100,6 +107,8 @@ namespace AutoSellerNS
tbCFTimeDown.Text = Config.GetTimeDown().ToString(); tbCFTimeDown.Text = Config.GetTimeDown().ToString();
tbCFIgnorePrice.Text = Config.GetIgnorePrice().ToString(); tbCFIgnorePrice.Text = Config.GetIgnorePrice().ToString();
cbMockTrading.Checked = Config.GetMockTrading();
m_CybosHelper = new CybosHelper(this); m_CybosHelper = new CybosHelper(this);
m_iCurPricePanelWith = 240; m_iCurPricePanelWith = 240;
@@ -114,28 +123,6 @@ namespace AutoSellerNS
m_Timer.Start(); m_Timer.Start();
} }
private void Timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
if(m_bSell == false)
return;
var ClonedList = m_NCItems.ConvertAll(s => s);
foreach(var NCItem in ClonedList)
{
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;
int iAskPrice = CurItem.m_aiAskPrice[0];
m_CybosHelper.CorrectionItem(NCItem.m_strCode, NCItem.m_iOrderNo, NCItem.m_iRemainCnt, iAskPrice);
NCItem.m_Time = DateTime.Now;
Util.Log(Util.LOG_TYPE.SELL, string.Format("[{0}] 정정 주문 (주문번호: {1})", NCItem.m_strCodeName, NCItem.m_iOrgOrderNo));
}
}
}
public void SetAccountList(string[] aAccountList) public void SetAccountList(string[] aAccountList)
{ {
cbAccount.Items.Clear(); cbAccount.Items.Clear();
@@ -157,9 +144,9 @@ namespace AutoSellerNS
splitContainer2.SplitterDistance = iDist; splitContainer2.SplitterDistance = iDist;
} }
private void btCybos_Click(object sender, EventArgs e) private async void btCybos_Click(object sender, EventArgs e)
{ {
m_CybosHelper.InitCybos(); await m_CybosHelper.InitCybosAsync();
btCybos.Primary = false; btCybos.Primary = false;
btCybos.Enabled = false; btCybos.Enabled = false;
@@ -167,147 +154,237 @@ namespace AutoSellerNS
btUpdate.Enabled = true; btUpdate.Enabled = true;
btSell.Enabled = true; btSell.Enabled = true;
//btUpdate_Click(null, null); UpdateItem();
} }
private void AddItem(ITEM Item) void SyncItems(List<ITEM> OldItems, List<ITEM> NewItems)
{ {
m_Items.Add(Item); foreach(ITEM newItem in NewItems)
if(lvItems.InvokeRequired)
{ {
CybosHelper.STOCK_CUR_ITEM ItemCur = m_CybosHelper.GetItem(Item.m_strCode); ITEM oldItem = OldItems.FirstOrDefault(s => s.m_strCode == newItem.m_strCode);
if (oldItem != null)
lvItems.Invoke(new Action(() => { {
lvItems.Items.Add(new ListViewItem(new string[] { // update
Item.m_strCode, oldItem.m_iItemCnt = newItem.m_iItemCnt;
Item.m_strCodeName, oldItem.m_iAssessedValue = newItem.m_iAssessedValue;
string.Format("{0:n0}", Item.m_iCurPrice), oldItem.m_iValuationGains = newItem.m_iValuationGains;
string.Format("{0:n0}", Item.m_iAvailableQuantity), oldItem.m_dYield = newItem.m_dYield;
string.Format("{0:n2}", Item.m_dBookUnitPrice), oldItem.m_iAvailableQuantity = newItem.m_iAvailableQuantity;
string.Format("{0:n0}", Item.m_iProfitUnitPrice), oldItem.m_dBookUnitPrice = newItem.m_dBookUnitPrice;
string.Format("{0:n0}", Item.m_iAssessedValue), oldItem.m_iProfitUnitPrice = newItem.m_iProfitUnitPrice;
string.Format("{0:n0}", Item.m_iValuationGains), oldItem.m_iCurPrice = newItem.m_iCurPrice;
string.Format("{0:n2}", Item.m_dYield),
ItemCur != null ? string.Format("{0:n0}", ItemCur.m_iMaxPrice) : "",
ItemCur != null ? string.Format("{0:n2}", ItemCur.m_dCheckCountLimit) : "",
ItemCur != null ? string.Format("{0:n0}", ItemCur.m_iCheckCount) : "",
}));
var listviewItem = lvItems.Items[lvItems.Items.Count - 1];
lvItems.Items[lvItems.Items.Count - 1].UseItemStyleForSubItems = false;
lvItems.Items[lvItems.Items.Count - 1].SubItems[chValuation.Index].ForeColor = (Item.m_iValuationGains > 0) ? Color.Red : (Item.m_iValuationGains < 0) ? Color.Blue : Color.Black;
lvItems.Items[lvItems.Items.Count - 1].SubItems[chYield.Index].ForeColor = (Item.m_dYield > 0) ? Color.Red : (Item.m_dYield < 0) ? Color.Blue : Color.Black;
m_CybosHelper.Subscribe(Item);
}));
} }
else else
{ {
CybosHelper.STOCK_CUR_ITEM ItemCur = m_CybosHelper.GetItem(Item.m_strCode); // add
m_Items.Add(newItem);
lvItems.Items.Add(new ListViewItem(new string[] { m_CybosHelper.Subscribe(newItem);
Item.m_strCode,
Item.m_strCodeName,
string.Format("{0:n0}", Item.m_iCurPrice),
string.Format("{0:n0}", Item.m_iAvailableQuantity),
string.Format("{0:n2}", Item.m_dBookUnitPrice),
string.Format("{0:n0}", Item.m_iProfitUnitPrice),
string.Format("{0:n0}", Item.m_iAssessedValue),
string.Format("{0:n0}", Item.m_iValuationGains),
string.Format("{0:n2}", Item.m_dYield),
ItemCur != null ? string.Format("{0:n0}", ItemCur.m_iMaxPrice) : "",
ItemCur != null ? string.Format("{0:n2}", ItemCur.m_dCheckCountLimit) : "",
ItemCur != null ? string.Format("{0:n0}", ItemCur.m_iCheckCount) : "",
}));
var listviewItem = lvItems.Items[lvItems.Items.Count - 1];
lvItems.Items[lvItems.Items.Count - 1].UseItemStyleForSubItems = false;
lvItems.Items[lvItems.Items.Count - 1].SubItems[chValuation.Index].ForeColor = (Item.m_iValuationGains > 0) ? Color.Red : (Item.m_iValuationGains < 0) ? Color.Blue : Color.Black;
lvItems.Items[lvItems.Items.Count - 1].SubItems[chYield.Index].ForeColor = (Item.m_dYield > 0) ? Color.Red : (Item.m_dYield < 0) ? Color.Blue : Color.Black;
m_CybosHelper.Subscribe(Item);
} }
} }
// remove
OldItems.RemoveAll(s => (NewItems.Any(k => k.m_strCode == s.m_strCode) == false));
}
void SyncListViewItems(List<ITEM> Items)
{
lvItems.Items.Cast<ListViewItem>().ToList().RemoveAll(s => (Items.Any(t => t.m_strCode == s.SubItems[chCode.Index].Text) == false));
foreach(ITEM item in Items)
{
ListViewItem row = lvItems.Items.Cast<ListViewItem>().FirstOrDefault(s => s.SubItems[chCode.Index].Text == item.m_strCode);
if(row == null)
{
// insert
row = lvItems.Items.Add(new ListViewItem(new string[12]));
row.SubItems[chCode.Index].Text = item.m_strCode;
row.SubItems[chCodeName.Index].Text = item.m_strCodeName;
row.UseItemStyleForSubItems = false;
}
// update
CybosHelper.STOCK_CUR_ITEM ItemCur = m_CybosHelper.GetItem(item.m_strCode);
row.SubItems[chCurPrice.Index].Text = string.Format("{0:n0}", item.m_iCurPrice);
row.SubItems[chCount.Index].Text = string.Format("{0:n0}", item.m_iAvailableQuantity);
row.SubItems[chBookValue.Index].Text = string.Format("{0:n2}", item.m_dBookUnitPrice);
row.SubItems[chCapitalGains.Index].Text = string.Format("{0:n0}", item.m_iProfitUnitPrice);
row.SubItems[chAssessedValue.Index].Text = string.Format("{0:n0}", item.m_iAssessedValue / 1000);
row.SubItems[chValuation.Index].Text = string.Format("{0:n0}", item.m_iValuationGains / 1000);
row.SubItems[chYield.Index].Text = string.Format("{0:n2}", item.m_dYield);
row.SubItems[chMaxPrice.Index].Text = ItemCur != null ? string.Format("{0:n0}", ItemCur.m_iMaxPrice) : "";
row.SubItems[chCheckCountLimit.Index].Text = ItemCur != null ? string.Format("{0:n2}", ItemCur.m_dCheckCountLimit) : "";
row.SubItems[chCheckCount.Index].Text = ItemCur != null ? string.Format("{0:n0}", ItemCur.m_iCheckCount) : "";
row.SubItems[chValuation.Index].ForeColor = (item.m_iValuationGains > 0) ? Color.Red : (item.m_iValuationGains < 0) ? Color.Blue : Color.Black;
row.SubItems[chYield.Index].ForeColor = (item.m_dYield > 0) ? Color.Red : (item.m_dYield < 0) ? Color.Blue : Color.Black;
}
}
public async void UpdateItem()
{
await m_UpdateSemaphore.WaitAsync();
List<ITEM> Items = await m_CybosHelper.UpdateItemsAsync();
SyncItems(m_Items, Items);
SyncListViewItems(m_Items);
m_UpdateSemaphore.Release();
}
void SyncNCItems(List<NCITEM> oldList, List<NCITEM> newList)
{
oldList.RemoveAll(s => newList.Any(t => t.m_iOrgOrderNo == s.m_iOrgOrderNo) == false);
foreach (var NCItem in newList)
{
if (oldList.Any(s => s.m_iOrgOrderNo == NCItem.m_iOrgOrderNo) == false)
{
NCItem.m_Time = DateTime.Now;
oldList.Add(NCItem);
}
}
}
void SyncNCListVIewItems(List<NCITEM> NCItems)
{
lvNCItem.Items.Cast<ListViewItem>().ToList().RemoveAll(r =>
NCItems.Any(t => (t.m_iOrgOrderNo.ToString() == r.SubItems[chNCOrgOrderNo.Index].Text) == false));
foreach (var NCItem in NCItems)
{
ListViewItem row = lvNCItem.Items.Cast<ListViewItem>().FirstOrDefault(r => r.SubItems[chNCOrgOrderNo.Index].Text == NCItem.m_iOrgOrderNo.ToString());
if(row == null)
{
// insert
row = new ListViewItem(new string[7]);
row.SubItems[chNCOrderNo.Index].Text = NCItem.m_iOrderNo.ToString();
row.SubItems[chNCOrgOrderNo.Index].Text = NCItem.m_iOrgOrderNo.ToString();
row.SubItems[chNCCode.Index].Text = NCItem.m_strCode;
row.SubItems[chNCCodeName.Index].Text = NCItem.m_strCodeName;
row.SubItems[chNCType.Index].Text = NCItem.m_strDesc;
row.UseItemStyleForSubItems = false;
lvNCItem.Items.Add(row);
}
// update
row.SubItems[chNCPrice.Index].Text = NCItem.m_iOrderPrice.ToString("n0");
row.SubItems[chNCCount.Index].Text = NCItem.m_iRemainCnt.ToString("n0");
row.SubItems[chNCType.Index].ForeColor = NCItem.m_bAsk ? Color.Blue : Color.Red;
}
}
public async void UpdateNCItem()
{
await m_NCUpdateSemaphore.WaitAsync();
List<NCITEM> NCItems = await m_CybosHelper.UpdateNCAsync();
SyncNCItems(m_NCItems, NCItems);
SyncNCListVIewItems(m_NCItems);
m_NCUpdateSemaphore.Release();
}
async void CorrectItems()
{
if (m_bSell == false)
return;
var ClonedList = m_NCItems.ConvertAll(s => s);
foreach (var NCItem in ClonedList)
{
if (NCItem.m_bAsk == true && DateTime.Now - NCItem.m_Time >= TimeSpan.FromSeconds(3))
{
var CurItem = m_CybosHelper.GetItem(NCItem.m_strCode);
if (CurItem == null)
continue;
int iPrice = CurItem.m_aiBidPrice[0];
await m_CybosHelper.CorrectionItem(NCItem.m_strCode, NCItem.m_iOrderNo, NCItem.m_iRemainCnt, iPrice);
NCItem.m_Time = DateTime.Now;
Util.Log(Util.LOG_TYPE.SELL, string.Format("[{0}] 정정 주문 (주문번호: {1})", NCItem.m_strCodeName, NCItem.m_iOrgOrderNo));
}
}
}
private void Timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
CorrectItems();
}
private void btUpdate_Click(object sender, EventArgs e) private void btUpdate_Click(object sender, EventArgs e)
{ {
// 잔고 UpdateItem();
var Items = m_CybosHelper.UpdateItems();
m_Items.Clear();
lvItems.Items.Clear();
foreach(var Item in Items)
AddItem(Item);
// 미체결
UpdateNC();
} }
void UpdateNC() public class HttpResult
{ {
var NCItems = m_CybosHelper.UpdateNC(); public HttpStatusCode StatusCode;
m_NCItems = NCItems; public string strData;
};
lvNCItem.Items.Clear(); async Task<HttpResult> Request(string url, HttpMethod method,
if(lvNCItem.InvokeRequired) string data = null,
Dictionary<string, string> headers = null)
{ {
lvNCItem.Invoke(new Action(() => { HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
foreach(var NCItem in NCItems) req.Method = method.ToString();
req.ContentType = "application/json";
if (headers != null)
{ {
ListViewItem viewItem = new ListViewItem(new string[] { foreach (var kv in headers)
NCItem.m_iOrderNo.ToString(), req.Headers[kv.Key] = kv.Value;
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;
}
}));
}
else
{
foreach(var NCItem in NCItems)
{
ListViewItem viewItem = new ListViewItem(new string[] {
NCItem.m_iOrderNo.ToString(),
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;
}
}
} }
public void UpdateItem(string strCode, string strCodeName, bool bBid, int iConclusionCnt, int iRemainCnt, int iBookValue) if (data != null)
{ {
// 잔고 Stream writeStream = req.GetRequestStream();
var Items = m_CybosHelper.UpdateItems(); byte[] buffer = Encoding.UTF8.GetBytes(data);
await writeStream.WriteAsync(buffer, 0, buffer.Length);
m_Items.Clear();
lvItems.Items.Clear();
foreach(var Item in Items)
AddItem(Item);
} }
public void UpdateNCItem() HttpWebResponse resp = null;
HttpResult result = null;
try
{ {
UpdateNC(); resp = await req.GetResponseAsync() as HttpWebResponse;
}
catch (WebException ex)
{
if (ex.Status == WebExceptionStatus.ProtocolError)
resp = ex.Response as HttpWebResponse;
}
finally
{
Stream readStream = resp.GetResponseStream();
StreamReader sr = new StreamReader(readStream);
result = new HttpResult()
{
StatusCode = resp.StatusCode,
strData = await sr.ReadToEndAsync()
};
}
return result;
}
async void SendConfiguration()
{
var oData = new
{
Mac = NetworkInterface.GetAllNetworkInterfaces()[0].GetPhysicalAddress().ToString(),
Date = DateTime.Now.ToString("yyyy-MM-dd"),
Config = Config.GetAllConfig(),
};
string serverURL = "http://mjjo53.us.to:9200";
string index = "trading-autoseller";
string doc = "default";
string id = $"{oData.Mac}-{oData.Date}";
JObject data = JObject.FromObject(oData);
string json = data.ToString(Newtonsoft.Json.Formatting.Indented);
Dictionary<string, string> headers = new Dictionary<string, string>();
headers["Authorization"] = "Basic dHJhZGVyOnNidG1hb2Fv";
var result = await Request($"{serverURL}/{index}/{doc}/{id}?pretty", HttpMethod.Post, json, headers);
} }
private void btSell_Click(object sender, EventArgs e) private void btSell_Click(object sender, EventArgs e)
@@ -317,12 +394,14 @@ namespace AutoSellerNS
if(m_bSell == true) if(m_bSell == true)
{ {
FileTransfer ft = new FileTransfer(); //FileTransfer ft = new FileTransfer();
string today = DateTime.Now.ToString("yyyy-MM-dd"); //string today = DateTime.Now.ToString("yyyy-MM-dd");
string macAddr = NetworkInterface.GetAllNetworkInterfaces()[0].GetPhysicalAddress().ToString(); //string macAddr = NetworkInterface.GetAllNetworkInterfaces()[0].GetPhysicalAddress().ToString();
ft.SendDir("/configure", macAddr + "/AutoSeller/" + today); //ft.SendDir("/configure", macAddr + "/AutoSeller/" + today);
//ft.SendDir("/log", macAddr + "/AutoSeller"); //ft.SendDir("/log", macAddr + "/AutoSeller");
//ft.SendDir("/simulation", macAddr + "/AutoSeller"); //ft.SendDir("/simulation", macAddr + "/AutoSeller");
SendConfiguration();
} }
} }
@@ -342,51 +421,31 @@ namespace AutoSellerNS
Item.m_iValuationGains = (iPrice-Item.m_iProfitUnitPrice)*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; Item.m_dYield = (iPrice-Item.m_iProfitUnitPrice)*100 / (double)Item.m_iProfitUnitPrice;
Action update = delegate {
ListViewItem row = lvItems.Items.Cast<ListViewItem>().FirstOrDefault(s => s.SubItems[chCode.Index].Text == strCode);
if (row == default(ListViewItem))
return;
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 / 1000);
row.SubItems[chValuation.Index].Text = string.Format("{0:n0}", Item.m_iValuationGains / 1000);
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);
row.SubItems[chCheckCount.Index].Text = string.Format("{0:n0}", iCheckCount);
};
if (lvItems.InvokeRequired) if (lvItems.InvokeRequired)
{ lvItems.BeginInvoke(update);
lvItems.Invoke(new Action(() =>
{
ListViewItem row = lvItems.Items.Cast<ListViewItem>().FirstOrDefault(s => s.SubItems[chCode.Index].Text == strCode);
if (row == default(ListViewItem))
return;
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);
row.SubItems[chCheckCount.Index].Text = string.Format("{0:n0}", iCheckCount);
}));
}
else else
{ update();
ListViewItem row = lvItems.Items.Cast<ListViewItem>().FirstOrDefault(s => s.SubItems[chCode.Index].Text == strCode);
if (row == default(ListViewItem))
return;
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);
row.SubItems[chCheckCount.Index].Text = string.Format("{0:n0}", iCheckCount);
}
if(strCode == m_strSelectedCode) if(strCode == m_strSelectedCode)
{ {
if (lvCurPrice.InvokeRequired) lvCurPrice.BeginInvoke((MethodInvoker)(() => {
{
lvCurPrice.Invoke(new Action(() => {
lvCurPrice.Items[10].SubItems[chCallPrice.Index].Text = string.Format("{0:n0}", Item.m_iCurPrice); lvCurPrice.Items[10].SubItems[chCallPrice.Index].Text = string.Format("{0:n0}", Item.m_iCurPrice);
})); }));
} }
else
{
lvCurPrice.Items[10].SubItems[chCallPrice.Index].Text = string.Format("{0:n0}", Item.m_iCurPrice);
}
}
} }
public void OnReceivedCall(string strCode, int iCurPrice, int[] aiBidPrice, int[] aiBidCount, int[] aiAskPrice, int[] aiAskCount) public void OnReceivedCall(string strCode, int iCurPrice, int[] aiBidPrice, int[] aiBidCount, int[] aiAskPrice, int[] aiAskCount)
@@ -398,17 +457,14 @@ namespace AutoSellerNS
if (Item == default(ITEM)) if (Item == default(ITEM))
return; return;
if (lvCurPrice.InvokeRequired) Action update = delegate {
{ if (iCurPrice > 0)
lvCurPrice.Invoke(new Action(() => {
if(iCurPrice > 0)
lvCurPrice.Items[10].SubItems[chCallPrice.Index].Text = string.Format("{0:n0}", iCurPrice); lvCurPrice.Items[10].SubItems[chCallPrice.Index].Text = string.Format("{0:n0}", iCurPrice);
for (int i = 0; i < 10; i++) for (int i = 0; i < 10; i++)
{ {
lvCurPrice.Items[i].SubItems[chAskCount.Index].Text = string.Format("{0:n0}", aiAskCount[9-i]); lvCurPrice.Items[i].SubItems[chAskCount.Index].Text = string.Format("{0:n0}", aiAskCount[9 - i]);
lvCurPrice.Items[i].SubItems[chCallPrice.Index].Text = string.Format("{0:n0}", aiAskPrice[9-i]); lvCurPrice.Items[i].SubItems[chCallPrice.Index].Text = string.Format("{0:n0}", aiAskPrice[9 - i]);
} }
for (int i = 0; i < 10; i++) for (int i = 0; i < 10; i++)
@@ -416,25 +472,12 @@ namespace AutoSellerNS
lvCurPrice.Items[11 + i].SubItems[chBidCount.Index].Text = string.Format("{0:n0}", aiBidCount[i]); lvCurPrice.Items[11 + i].SubItems[chBidCount.Index].Text = string.Format("{0:n0}", aiBidCount[i]);
lvCurPrice.Items[11 + i].SubItems[chCallPrice.Index].Text = string.Format("{0:n0}", aiBidPrice[i]); lvCurPrice.Items[11 + i].SubItems[chCallPrice.Index].Text = string.Format("{0:n0}", aiBidPrice[i]);
} }
})); };
}
if (lvCurPrice.InvokeRequired)
lvCurPrice.BeginInvoke(update);
else else
{ update();
if(iCurPrice > 0)
lvCurPrice.Items[10].SubItems[chCallPrice.Index].Text = string.Format("{0:n0}", iCurPrice);
for (int i = 0; i < 10; i++)
{
lvCurPrice.Items[i].SubItems[chAskCount.Index].Text = string.Format("{0:n0}", aiAskCount[9-i]);
lvCurPrice.Items[i].SubItems[chCallPrice.Index].Text = string.Format("{0:n0}", aiAskPrice[9-i]);
}
for (int i = 0; i < 10; i++)
{
lvCurPrice.Items[11+i].SubItems[chBidCount.Index].Text = string.Format("{0:n0}", aiBidCount[i]);
lvCurPrice.Items[11+i].SubItems[chCallPrice.Index].Text = string.Format("{0:n0}", aiBidPrice[i]);
}
}
} }
public int GetSellableCount(string strCode) public int GetSellableCount(string strCode)
@@ -499,6 +542,8 @@ namespace AutoSellerNS
double.TryParse(tbCFTimeDown.Text, out dTimeDown); double.TryParse(tbCFTimeDown.Text, out dTimeDown);
int.TryParse(tbCFIgnorePrice.Text, out iIgnorePrice); int.TryParse(tbCFIgnorePrice.Text, out iIgnorePrice);
Config.SetVolatility(iListSize, dFastSD, dFastUp, dFastDown, dSlowSD, dSlowUp, dSlowDown, iTimeLimit, dTimeDown, iIgnorePrice); Config.SetVolatility(iListSize, dFastSD, dFastUp, dFastDown, dSlowSD, dSlowUp, dSlowDown, iTimeLimit, dTimeDown, iIgnorePrice);
Config.SetMockTrading(cbMockTrading.Checked);
} }
#region Simulation #region Simulation
@@ -514,5 +559,6 @@ namespace AutoSellerNS
helper.StartSimuation2(); helper.StartSimuation2();
} }
#endregion #endregion
} }
} }

View File

@@ -76,6 +76,10 @@
<HintPath>packages\MaterialSkin.0.2.1\lib\MaterialSkin.dll</HintPath> <HintPath>packages\MaterialSkin.0.2.1\lib\MaterialSkin.dll</HintPath>
<Private>True</Private> <Private>True</Private>
</Reference> </Reference>
<Reference Include="Newtonsoft.Json, Version=11.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>packages\Newtonsoft.Json.11.0.2\lib\net45\Newtonsoft.Json.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" /> <Reference Include="System" />
<Reference Include="System.Core" /> <Reference Include="System.Core" />
<Reference Include="System.Web" /> <Reference Include="System.Web" />

View File

@@ -32,6 +32,7 @@ namespace AutoSellerNS
m_Data.Add("time-limit", 5); m_Data.Add("time-limit", 5);
m_Data.Add("time-down", 0.02); m_Data.Add("time-down", 0.02);
m_Data.Add("ignore-price", 50000); m_Data.Add("ignore-price", 50000);
m_Data.Add("mock-trading", false);
Load(); Load();
} }
@@ -144,5 +145,12 @@ namespace AutoSellerNS
public static int GetTimeLimit() { return (int)m_Data["time-limit"]; } public static int GetTimeLimit() { return (int)m_Data["time-limit"]; }
public static double GetTimeDown() { return (double)m_Data["time-down"]; } public static double GetTimeDown() { return (double)m_Data["time-down"]; }
public static int GetIgnorePrice() { return (int)m_Data["ignore-price"]; } public static int GetIgnorePrice() { return (int)m_Data["ignore-price"]; }
public static void SetMockTrading(bool bMockTrading) { m_Data["mock-trading"] = bMockTrading; Save(); }
public static bool GetMockTrading() { return (bool)m_Data["mock-trading"]; }
public static Dictionary<string, object> GetAllConfig()
{
return m_Data;
}
} }
} }

View File

@@ -51,7 +51,7 @@ namespace AutoSellerNS
int m_iPrevTime = 0; int m_iPrevTime = 0;
public void OnRecievedPrice() public async void OnRecievedPrice()
{ {
bool bOpeningHour = (m_StockCur.GetHeaderValue(19) == '2'); bool bOpeningHour = (m_StockCur.GetHeaderValue(19) == '2');
m_iCurPrice = m_StockCur.GetHeaderValue(13); m_iCurPrice = m_StockCur.GetHeaderValue(13);
@@ -117,7 +117,7 @@ namespace AutoSellerNS
if(m_iCheckCount >= m_dCheckCountLimit && m_Listener.IsSelling() == true) if(m_iCheckCount >= m_dCheckCountLimit && m_Listener.IsSelling() == true)
{ {
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]);
Util.Log(Util.LOG_TYPE.SELL, string.Format("[조건 완료 매도] {0} ({1}회) (현재가 {2:n0}원, 최고가 {3:n0}원)", Util.Log(Util.LOG_TYPE.SELL, string.Format("[조건 완료 매도] {0} ({1}회) (현재가 {2:n0}원, 최고가 {3:n0}원)",
m_strCodeName, m_strCodeName,
Config.GetBidCount(), Config.GetBidCount(),
@@ -129,7 +129,7 @@ namespace AutoSellerNS
m_iTrailingCount++; m_iTrailingCount++;
if(m_iTrailingCount >= Config.GetTrailingCnt() && m_Listener.IsSelling() == true) if(m_iTrailingCount >= Config.GetTrailingCnt() && m_Listener.IsSelling() == true)
{ {
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]);
Util.Log(Util.LOG_TYPE.SELL, string.Format("[트레일링 매도] {0} ({1}% {2}회) (현재가 {3:n0}원, 최고가 {4:n0}원)", Util.Log(Util.LOG_TYPE.SELL, string.Format("[트레일링 매도] {0} ({1}% {2}회) (현재가 {3:n0}원, 최고가 {4:n0}원)",
m_strCodeName, m_strCodeName,
Config.GetTrailingRate(), Config.GetTrailingRate(),
@@ -140,7 +140,7 @@ namespace AutoSellerNS
if(iTimeDiff >= Config.GetTimeLimit() && m_Listener.IsSelling() == true) if(iTimeDiff >= Config.GetTimeLimit() && m_Listener.IsSelling() == true)
{ {
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]);
Util.Log(Util.LOG_TYPE.SELL, string.Format("[시간제한 매도] {0} ({1}초) (현재가 {2:n0}원, 최고가 {3:n0}원)", Util.Log(Util.LOG_TYPE.SELL, string.Format("[시간제한 매도] {0} ({1}초) (현재가 {2:n0}원, 최고가 {3:n0}원)",
m_strCodeName, m_strCodeName,
iTimeDiff, iTimeDiff,
@@ -236,6 +236,14 @@ namespace AutoSellerNS
m_CpConclusion.Subscribe(); m_CpConclusion.Subscribe();
} }
public async Task InitCybosAsync()
{
await Task.Run(() =>
{
InitCybos();
});
}
public void SavePrice(STOCK_CUR_ITEM item) public void SavePrice(STOCK_CUR_ITEM item)
{ {
if (Directory.Exists(Util.GetLogPath()) == false) if (Directory.Exists(Util.GetLogPath()) == false)
@@ -259,37 +267,36 @@ namespace AutoSellerNS
public List<AutoSeller.ITEM> UpdateItems() public List<AutoSeller.ITEM> UpdateItems()
{ {
List<AutoSeller.ITEM> aItems = new List<AutoSeller.ITEM>(); List<AutoSeller.ITEM> aItems = new List<AutoSeller.ITEM>();
if (Config.GetAccount() == "") if (Config.GetAccount() == "")
return aItems; return aItems;
m_6033.SetInputValue(0, Config.GetAccount()); m_6033.SetInputValue(0, Config.GetAccount());
m_6033.SetInputValue(1, Config.GetSubAccount()); m_6033.SetInputValue(1, Config.GetSubAccount());
m_6033.BlockRequest2(1); m_6033.BlockRequest2(0);
string strCodeList = ""; string strCodeList = "";
bool bContinue = true; bool bContinue = true;
while(bContinue == true) while (bContinue == true)
{ {
int iCount = m_6033.GetHeaderValue(7); int iCount = m_6033.GetHeaderValue(7);
for(int i = 0; i < iCount; i++) for (int i = 0; i < iCount; i++)
{ {
AutoSeller.ITEM Item = new AutoSeller.ITEM(); AutoSeller.ITEM Item = new AutoSeller.ITEM();
Item.m_strCodeName = m_6033.GetDataValue(0, i); Item.m_strCodeName = m_6033.GetDataValue(0, i);
if(Item.m_strCodeName != "") if (Item.m_strCodeName != "")
{ {
Item.m_strCode = m_6033.GetDataValue(12, i); Item.m_strCode = m_6033.GetDataValue(12, i);
Item.m_iItemCnt = m_6033.GetDataValue(7, i); Item.m_iItemCnt = m_6033.GetDataValue(7, i);
Item.m_iAssessedValue = m_6033.GetDataValue(9, i); Item.m_iAssessedValue = m_6033.GetDataValue(9, i) / 1000;
Item.m_iValuationGains = m_6033.GetDataValue(10, i); Item.m_iValuationGains = m_6033.GetDataValue(10, i) / 1000;
Item.m_dYield = m_6033.GetDataValue(11, i); Item.m_dYield = m_6033.GetDataValue(11, i);
Item.m_iAvailableQuantity = m_6033.GetDataValue(15, i); Item.m_iAvailableQuantity = m_6033.GetDataValue(15, i);
Item.m_dBookUnitPrice = m_6033.GetDataValue(17, i); Item.m_dBookUnitPrice = m_6033.GetDataValue(17, i);
Item.m_iProfitUnitPrice = m_6033.GetDataValue(18, i); Item.m_iProfitUnitPrice = m_6033.GetDataValue(18, i);
if(strCodeList.Length > 0) if (strCodeList.Length > 0)
strCodeList += ","; strCodeList += ",";
strCodeList += Item.m_strCode; strCodeList += Item.m_strCode;
@@ -298,15 +305,16 @@ namespace AutoSellerNS
} }
bContinue = (m_6033.Continue != 0); bContinue = (m_6033.Continue != 0);
if(bContinue == true) bContinue = false;
m_6033.BlockRequest2(1); if (bContinue == true)
m_6033.BlockRequest2(0);
} }
if (strCodeList.Length > 0) if (strCodeList.Length > 0)
{ {
DSCBO1Lib.StockMst2 StockMst = new DSCBO1Lib.StockMst2(); DSCBO1Lib.StockMst2 StockMst = new DSCBO1Lib.StockMst2();
StockMst.SetInputValue(0, strCodeList); StockMst.SetInputValue(0, strCodeList);
StockMst.BlockRequest2(1); StockMst.BlockRequest2(0);
int iCnt = StockMst.GetHeaderValue(0); int iCnt = StockMst.GetHeaderValue(0);
for (int i = 0; i < iCnt; i++) for (int i = 0; i < iCnt; i++)
{ {
@@ -320,13 +328,13 @@ namespace AutoSellerNS
// sync // sync
List<string> aRemoveKeys = new List<string>(); List<string> aRemoveKeys = new List<string>();
foreach(var Item in m_aStockCur) foreach (var Item in m_aStockCur)
{ {
if(aItems.Any(s => s.m_strCode == Item.Key) == false) if (aItems.Any(s => s.m_strCode == Item.Key) == false)
aRemoveKeys.Add(Item.Key); aRemoveKeys.Add(Item.Key);
} }
foreach(var Key in aRemoveKeys) foreach (var Key in aRemoveKeys)
{ {
m_aStockCur[Key].m_StockCur.Unsubscribe(); m_aStockCur[Key].m_StockCur.Unsubscribe();
m_aStockCur[Key].m_Jpbid.Unsubscribe(); m_aStockCur[Key].m_Jpbid.Unsubscribe();
@@ -337,14 +345,16 @@ namespace AutoSellerNS
return aItems; return aItems;
} }
static int iUpdateNCIdx = 1; public async Task<List<AutoSeller.ITEM>> UpdateItemsAsync()
{
return await Task<List<AutoSeller.ITEM>>.Run(() =>
{
return UpdateItems();
});
}
public List<AutoSeller.NCITEM> UpdateNC() 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) while(GetLimitRemainCountTrade() < 1)
Thread.Sleep(500); Thread.Sleep(500);
@@ -353,14 +363,12 @@ namespace AutoSellerNS
CPTRADELib.CpTd5339 CP5339 = new CPTRADELib.CpTd5339(); CPTRADELib.CpTd5339 CP5339 = new CPTRADELib.CpTd5339();
CP5339.SetInputValue(0, Config.GetAccount()); CP5339.SetInputValue(0, Config.GetAccount());
CP5339.SetInputValue(1, Config.GetSubAccount()); CP5339.SetInputValue(1, Config.GetSubAccount());
CP5339.BlockRequest2(1); CP5339.BlockRequest2(0);
bool bContinue = true; bool bContinue = true;
while(bContinue) while(bContinue)
{ {
int iCnt = CP5339.GetHeaderValue(5); int iCnt = CP5339.GetHeaderValue(5);
Console.WriteLine("icnt : {0}", iCnt);
for(int i = 0; i<iCnt; i++) for(int i = 0; i<iCnt; i++)
{ {
AutoSeller.NCITEM Item = new AutoSeller.NCITEM(); AutoSeller.NCITEM Item = new AutoSeller.NCITEM();
@@ -373,20 +381,27 @@ namespace AutoSellerNS
Item.m_bAsk = (CP5339.GetDataValue(13, i) == "1"); Item.m_bAsk = (CP5339.GetDataValue(13, i) == "1");
Item.m_iOrderNo = CP5339.GetDataValue(1, i); Item.m_iOrderNo = CP5339.GetDataValue(1, i);
Item.m_iOrgOrderNo = CP5339.GetDataValue(2, i); Item.m_iOrgOrderNo = CP5339.GetDataValue(2, i);
if (Item.m_iOrgOrderNo == 0)
Item.m_iOrgOrderNo = Item.m_iOrderNo;
NCItems.Add(Item); NCItems.Add(Item);
} }
bContinue = (CP5339.Continue != 0); bContinue = (CP5339.Continue != 0);
if(bContinue) if(bContinue)
CP5339.BlockRequest2(1); CP5339.BlockRequest2(0);
} }
Util.Log(Util.LOG_TYPE.DEBUG, string.Format("UpdateNC End ({0})", iIdx));
return NCItems; return NCItems;
} }
public async Task<List<AutoSeller.NCITEM>> UpdateNCAsync()
{
return await Task<List<AutoSeller.NCITEM>>.Run(() => {
return UpdateNC();
});
}
private void CpConclusion_Received() private void CpConclusion_Received()
{ {
string strType = m_CpConclusion.GetHeaderValue(14); string strType = m_CpConclusion.GetHeaderValue(14);
@@ -416,7 +431,7 @@ namespace AutoSellerNS
switch (iType) switch (iType)
{ {
case 1: // 체결 case 1: // 체결
m_Listener.UpdateItem(strCode, strCodeName, bBid, iConclusionCnt, iRemainCnt, iBookValue); m_Listener.UpdateItem();
m_Listener.UpdateNCItem(); 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)); 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));
break; break;
@@ -432,7 +447,7 @@ namespace AutoSellerNS
case 4: // 접수 case 4: // 접수
m_Listener.UpdateNCItem(); 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)); 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 (bBid == true) if (bBid == false)
{ {
if(m_aStockCur.ContainsKey(strCode) == true) if(m_aStockCur.ContainsKey(strCode) == true)
{ {
@@ -489,7 +504,7 @@ namespace AutoSellerNS
DSCBO1Lib.StockJpbid2 JpBid = new DSCBO1Lib.StockJpbid2(); DSCBO1Lib.StockJpbid2 JpBid = new DSCBO1Lib.StockJpbid2();
JpBid.SetInputValue(0, Item.m_strCode); JpBid.SetInputValue(0, Item.m_strCode);
JpBid.BlockRequest2(1); JpBid.BlockRequest2(0);
for(int i=0; i<10; i++) for(int i=0; i<10; i++)
{ {
StockCur.m_aiAskPrice[i] = JpBid.GetDataValue(0, i); StockCur.m_aiAskPrice[i] = JpBid.GetDataValue(0, i);
@@ -539,13 +554,11 @@ namespace AutoSellerNS
return (iValue/iUnit)*iUnit; return (iValue/iUnit)*iUnit;
} }
static int iSellIdx = 1; public async Task SellItem(string strCode, int iCnt, int iAskPrice)
public void SellItem(string strCode, int iCnt, int iAskPrice)
{ {
int iIdx = iSellIdx++; await Task.Run(() =>
Util.Log(Util.LOG_TYPE.DEBUG, string.Format("SellItem Start ({0})", iIdx)); {
int iSellPrice = iAskPrice - GetUnitValue(iAskPrice);
int iSellPrice = iAskPrice-GetUnitValue(iAskPrice);
CPTRADELib.CpTd0311 Td0311 = new CPTRADELib.CpTd0311(); CPTRADELib.CpTd0311 Td0311 = new CPTRADELib.CpTd0311();
Td0311.SetInputValue(0, "1"); Td0311.SetInputValue(0, "1");
@@ -556,16 +569,13 @@ namespace AutoSellerNS
Td0311.SetInputValue(5, iSellPrice); Td0311.SetInputValue(5, iSellPrice);
Td0311.SetInputValue(8, "01"); Td0311.SetInputValue(8, "01");
Td0311.BlockRequest2(1); Td0311.BlockRequest2(1);
});
Util.Log(Util.LOG_TYPE.DEBUG, string.Format("SellItem End ({0})", iIdx));
} }
static int iCancelIdx = 1; public async Task CancelItem(string strCode, int iOrgOrderNo)
public void CancelItem(string strCode, int iOrgOrderNo) {
await Task.Run(() =>
{ {
int iIdx = iCancelIdx++;
Util.Log(Util.LOG_TYPE.DEBUG, string.Format("CancelItem Start ({0})", iIdx));
CPTRADELib.CpTd0314 Td0314 = new CPTRADELib.CpTd0314(); CPTRADELib.CpTd0314 Td0314 = new CPTRADELib.CpTd0314();
Td0314.SetInputValue(1, iOrgOrderNo); Td0314.SetInputValue(1, iOrgOrderNo);
Td0314.SetInputValue(2, Config.GetAccount()); Td0314.SetInputValue(2, Config.GetAccount());
@@ -573,16 +583,20 @@ namespace AutoSellerNS
Td0314.SetInputValue(4, strCode); Td0314.SetInputValue(4, strCode);
Td0314.SetInputValue(5, 0); Td0314.SetInputValue(5, 0);
Td0314.BlockRequest2(1); Td0314.BlockRequest2(1);
});
Util.Log(Util.LOG_TYPE.DEBUG, string.Format("CancelItem End ({0})", iIdx));
} }
static int iCorrectIdx = 1; public async Task CorrectionItem(string strCode, int iOrgOrderNo, int iCnt, int iAskPrice)
public void CorrectionItem(string strCode, int iOrgOrderNo, int iCnt, int iAskPrice)
{ {
int iIdx = iCorrectIdx++; if(Config.GetMockTrading() == true)
Util.Log(Util.LOG_TYPE.DEBUG, string.Format("CorrectionItem Start ({0})", iIdx)); {
await CancelItem(strCode, iOrgOrderNo);
await SellItem(strCode, iCnt, iAskPrice);
return;
}
await Task.Run(() =>
{
int iSellPrice = iAskPrice; int iSellPrice = iAskPrice;
CPTRADELib.CpTd0313 Td0313 = new CPTRADELib.CpTd0313(); CPTRADELib.CpTd0313 Td0313 = new CPTRADELib.CpTd0313();
@@ -593,8 +607,7 @@ namespace AutoSellerNS
Td0313.SetInputValue(5, 0); Td0313.SetInputValue(5, 0);
Td0313.SetInputValue(6, iSellPrice); Td0313.SetInputValue(6, iSellPrice);
Td0313.BlockRequest2(1); Td0313.BlockRequest2(1);
});
Util.Log(Util.LOG_TYPE.DEBUG, string.Format("CorrectionItem End ({0})", iIdx));
} }
} }
} }

View File

@@ -1067,7 +1067,7 @@ namespace FluentFTP {
// seek to required offset // seek to required offset
fileData.Position = offset; fileData.Position = offset;
} catch (Exception ex2) { } catch (Exception) {
} }
} }
@@ -1208,12 +1208,15 @@ namespace FluentFTP {
Stream upStream = null; Stream upStream = null;
try { try {
long offset = 0; long offset = 0;
bool checkFileExistsAgain = false; //bool checkFileExistsAgain = false;
// check if the file exists, and skip, overwrite or append // check if the file exists, and skip, overwrite or append
if (existsMode == FtpExists.NoCheck) { if (existsMode == FtpExists.NoCheck)
checkFileExistsAgain = true; {
} else { //checkFileExistsAgain = true;
}
else
{
if (!fileExistsKnown) { if (!fileExistsKnown) {
fileExists = await FileExistsAsync(remotePath); fileExists = await FileExistsAsync(remotePath);
} }
@@ -1254,7 +1257,7 @@ namespace FluentFTP {
// seek to required offset // seek to required offset
fileData.Position = offset; fileData.Position = offset;
} catch (Exception ex2) { } catch (Exception) {
} }
} }

View File

@@ -313,7 +313,7 @@ namespace FluentFTP {
try { try {
stream.Listen(m_stream.LocalEndPoint.Address, port); stream.Listen(m_stream.LocalEndPoint.Address, port);
success = true; success = true;
} catch (SocketException se) { } catch (SocketException) {
#if NETFX #if NETFX
// Already in use // Already in use
if (se.ErrorCode != 10048) if (se.ErrorCode != 10048)
@@ -448,7 +448,7 @@ namespace FluentFTP {
stream.Listen(m_stream.LocalEndPoint.Address, port); stream.Listen(m_stream.LocalEndPoint.Address, port);
success = true; success = true;
} }
catch (SocketException se) catch (SocketException)
{ {
#if NETFX #if NETFX
// Already in use // Already in use

View File

@@ -67,7 +67,7 @@ namespace AutoSellerNS
CPStockBid.SetInputValue(2, 20000); CPStockBid.SetInputValue(2, 20000);
CPStockBid.SetInputValue(3, 'C'); CPStockBid.SetInputValue(3, 'C');
CPStockBid.SetInputValue(4, "2000"); CPStockBid.SetInputValue(4, "2000");
CPStockBid.BlockRequest2(1); CPStockBid.BlockRequest2(0);
List<object[]> aaRows = new List<object[]>(); List<object[]> aaRows = new List<object[]>();
@@ -93,7 +93,7 @@ namespace AutoSellerNS
{ {
while(m_CybosHelper.GetLimitRemainCountRQ() < 2) while(m_CybosHelper.GetLimitRemainCountRQ() < 2)
Thread.Sleep(100); Thread.Sleep(100);
CPStockBid.BlockRequest2(1); CPStockBid.BlockRequest2(0);
} }
m_tbLogView.AppendText(string.Format("RequestRQ({0}) ", m_CybosHelper.GetLimitRemainCountRQ())); m_tbLogView.AppendText(string.Format("RequestRQ({0}) ", m_CybosHelper.GetLimitRemainCountRQ()));
@@ -114,7 +114,7 @@ namespace AutoSellerNS
void InsertLog(string strMsg) void InsertLog(string strMsg)
{ {
m_tbLogView.Invoke(new Action(() => { m_tbLogView.BeginInvoke(new Action(() => {
int iPrevSelectionStart = m_tbLogView.SelectionStart; int iPrevSelectionStart = m_tbLogView.SelectionStart;
int iPrevSelectionLength = m_tbLogView.SelectionLength; int iPrevSelectionLength = m_tbLogView.SelectionLength;
bool bScroll = m_tbLogView.SelectionStart == m_tbLogView.TextLength; bool bScroll = m_tbLogView.SelectionStart == m_tbLogView.TextLength;
@@ -739,7 +739,7 @@ namespace AutoSellerNS
bHalfTrailing = m_AutoSeller.chSMHalfTrailing.Checked; bHalfTrailing = m_AutoSeller.chSMHalfTrailing.Checked;
string strMethod = ""; string strMethod = "";
m_AutoSeller.cbSMMethod.Invoke(new Action(() => { m_AutoSeller.cbSMMethod.BeginInvoke(new Action(() => {
strMethod = (string)m_AutoSeller.cbSMMethod.SelectedItem; strMethod = (string)m_AutoSeller.cbSMMethod.SelectedItem;
})); }));

18
Util.cs
View File

@@ -23,8 +23,6 @@ namespace AutoSellerNS
static string m_strLogFile = null; static string m_strLogFile = null;
static RichTextBox m_LogBox = null; static RichTextBox m_LogBox = null;
delegate void InsertLogDelegate(RichTextBox LogBox, LOG_TYPE enType, string strLog);
static InsertLogDelegate m_InsertLogDelegate = new InsertLogDelegate(InsertLog);
static object m_LogLock = new object(); static object m_LogLock = new object();
public static void SetLogView(RichTextBox logBox) public static void SetLogView(RichTextBox logBox)
@@ -42,14 +40,9 @@ namespace AutoSellerNS
if(IsDebugging() == false && enType == LOG_TYPE.DEBUG) if(IsDebugging() == false && enType == LOG_TYPE.DEBUG)
return; return;
if(LogBox.InvokeRequired) Action update = delegate {
{
LogBox.Invoke(m_InsertLogDelegate, LogBox, enType, strLog);
}
else
{
Color LogColor; Color LogColor;
switch(enType) switch (enType)
{ {
case LOG_TYPE.DEBUG: case LOG_TYPE.DEBUG:
LogColor = Color.Gray; LogColor = Color.Gray;
@@ -81,7 +74,12 @@ namespace AutoSellerNS
LogBox.SelectionStart = LogBox.TextLength; LogBox.SelectionStart = LogBox.TextLength;
LogBox.ScrollToCaret(); LogBox.ScrollToCaret();
} };
if (LogBox.InvokeRequired)
LogBox.BeginInvoke(update);
else
update();
} }
public static void Log(LOG_TYPE enType, string strLog) public static void Log(LOG_TYPE enType, string strLog)

View File

@@ -2,4 +2,5 @@
<packages> <packages>
<package id="EPPlus" version="4.1.0" targetFramework="net452" /> <package id="EPPlus" version="4.1.0" targetFramework="net452" />
<package id="MaterialSkin" version="0.2.1" targetFramework="net452" /> <package id="MaterialSkin" version="0.2.1" targetFramework="net452" />
<package id="Newtonsoft.Json" version="11.0.2" targetFramework="net452" />
</packages> </packages>