diff --git a/MainForm.Designer.cs b/MainForm.Designer.cs
index 9345ba6..7d4e050 100644
--- a/MainForm.Designer.cs
+++ b/MainForm.Designer.cs
@@ -56,11 +56,12 @@
this.btCancel = new System.Windows.Forms.Button();
this.tbBidMax = new System.Windows.Forms.TextBox();
this.label8 = new System.Windows.Forms.Label();
+ this.btBalance = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// textBox1
//
- this.textBox1.Location = new System.Drawing.Point(835, 413);
+ this.textBox1.Location = new System.Drawing.Point(836, 414);
this.textBox1.Multiline = true;
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(392, 217);
@@ -112,6 +113,7 @@
this.chBuy,
this.chBuyCnt});
this.lvWatch.FullRowSelect = true;
+ this.lvWatch.GridLines = true;
this.lvWatch.Location = new System.Drawing.Point(12, 12);
this.lvWatch.Name = "lvWatch";
this.lvWatch.Size = new System.Drawing.Size(807, 618);
@@ -283,11 +285,22 @@
this.label8.TabIndex = 11;
this.label8.Text = "~";
//
+ // btBalance
+ //
+ this.btBalance.Location = new System.Drawing.Point(883, 298);
+ this.btBalance.Name = "btBalance";
+ this.btBalance.Size = new System.Drawing.Size(75, 23);
+ this.btBalance.TabIndex = 17;
+ this.btBalance.Text = "잔고";
+ this.btBalance.UseVisualStyleBackColor = true;
+ this.btBalance.Click += new System.EventHandler(this.btBalance_Click);
+ //
// MainForm
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(1239, 642);
+ this.Controls.Add(this.btBalance);
this.Controls.Add(this.btCancel);
this.Controls.Add(this.btApply);
this.Controls.Add(this.tbSearchMin);
@@ -344,6 +357,7 @@
private System.Windows.Forms.Button btCancel;
private System.Windows.Forms.TextBox tbBidMax;
private System.Windows.Forms.Label label8;
+ private System.Windows.Forms.Button btBalance;
}
}
diff --git a/MainForm.cs b/MainForm.cs
index d70874f..40ad4ed 100644
--- a/MainForm.cs
+++ b/MainForm.cs
@@ -38,6 +38,8 @@ namespace upper_limit_crawler
ULDealing m_Dealing = new ULDealing(m_DataMgr);
ULOwn m_Own = new ULOwn(m_DataMgr);
+ ULBalanceDlg m_BalanceDlg = null;
+
public MainForm()
{
InitializeComponent();
@@ -141,5 +143,13 @@ namespace upper_limit_crawler
tbTrailing.Text = m_DataMgr.m_Setting.m_fTrailing.ToString("0.0");
tbLossCut.Text = m_DataMgr.m_Setting.m_fLossCut.ToString("0.0");
}
- }
+
+ private void btBalance_Click(object sender, EventArgs e)
+ {
+ if (m_BalanceDlg == null)
+ m_BalanceDlg = new ULBalanceDlg(m_DataMgr);
+
+ m_BalanceDlg.Show();
+ }
+ }
}
diff --git a/ULBalanceDlg.Designer.cs b/ULBalanceDlg.Designer.cs
new file mode 100644
index 0000000..a5c4785
--- /dev/null
+++ b/ULBalanceDlg.Designer.cs
@@ -0,0 +1,181 @@
+namespace upper_limit_crawler
+{
+ partial class ULBalanceDlg
+ {
+ ///
+ /// Required designer variable.
+ ///
+ private System.ComponentModel.IContainer components = null;
+
+ ///
+ /// Clean up any resources being used.
+ ///
+ /// true if managed resources should be disposed; otherwise, false.
+ protected override void Dispose(bool disposing)
+ {
+ if (disposing && (components != null))
+ {
+ components.Dispose();
+ }
+ base.Dispose(disposing);
+ }
+
+ #region Windows Form Designer generated code
+
+ ///
+ /// Required method for Designer support - do not modify
+ /// the contents of this method with the code editor.
+ ///
+ private void InitializeComponent()
+ {
+ this.lvBalance = new System.Windows.Forms.ListView();
+ this.chCode = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
+ this.chName = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
+ this.chUnitBuyPrice = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
+ this.chCurPrice = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
+ this.chBalance = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
+ this.chUnitBEP = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
+ this.chUnitProfit = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
+ this.chProfit = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
+ this.chProfitRate = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
+ this.btRefresh = new System.Windows.Forms.Button();
+ this.btSellAll = new System.Windows.Forms.Button();
+ this.btSell = new System.Windows.Forms.Button();
+ this.SuspendLayout();
+ //
+ // lvBalance
+ //
+ this.lvBalance.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
+ | System.Windows.Forms.AnchorStyles.Left)
+ | System.Windows.Forms.AnchorStyles.Right)));
+ this.lvBalance.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
+ this.chCode,
+ this.chName,
+ this.chUnitBuyPrice,
+ this.chCurPrice,
+ this.chBalance,
+ this.chUnitBEP,
+ this.chUnitProfit,
+ this.chProfit,
+ this.chProfitRate});
+ this.lvBalance.FullRowSelect = true;
+ this.lvBalance.GridLines = true;
+ this.lvBalance.Location = new System.Drawing.Point(12, 12);
+ this.lvBalance.MultiSelect = false;
+ this.lvBalance.Name = "lvBalance";
+ this.lvBalance.Size = new System.Drawing.Size(637, 362);
+ this.lvBalance.TabIndex = 0;
+ this.lvBalance.UseCompatibleStateImageBehavior = false;
+ this.lvBalance.View = System.Windows.Forms.View.Details;
+ this.lvBalance.ItemSelectionChanged += new System.Windows.Forms.ListViewItemSelectionChangedEventHandler(this.lvBalance_ItemSelectionChanged);
+ //
+ // chCode
+ //
+ this.chCode.Text = "종목코드";
+ //
+ // chName
+ //
+ this.chName.Text = "종목명";
+ this.chName.Width = 100;
+ //
+ // chUnitBuyPrice
+ //
+ this.chUnitBuyPrice.Text = "장부가";
+ this.chUnitBuyPrice.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
+ //
+ // chCurPrice
+ //
+ this.chCurPrice.Text = "현재가";
+ this.chCurPrice.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
+ //
+ // chBalance
+ //
+ this.chBalance.Text = "잔고수량";
+ this.chBalance.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
+ //
+ // chUnitBEP
+ //
+ this.chUnitBEP.Text = "손익단가";
+ this.chUnitBEP.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
+ //
+ // chUnitProfit
+ //
+ this.chUnitProfit.Text = "평가손익";
+ this.chUnitProfit.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
+ //
+ // chProfit
+ //
+ this.chProfit.Text = "평가금액";
+ this.chProfit.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
+ //
+ // chProfitRate
+ //
+ this.chProfitRate.Text = "수익률";
+ this.chProfitRate.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
+ this.chProfitRate.Width = 80;
+ //
+ // btRefresh
+ //
+ this.btRefresh.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
+ this.btRefresh.Location = new System.Drawing.Point(12, 380);
+ this.btRefresh.Name = "btRefresh";
+ this.btRefresh.Size = new System.Drawing.Size(75, 23);
+ this.btRefresh.TabIndex = 1;
+ this.btRefresh.Text = "갱신";
+ this.btRefresh.UseVisualStyleBackColor = true;
+ this.btRefresh.Click += new System.EventHandler(this.btRefresh_Click);
+ //
+ // btSellAll
+ //
+ this.btSellAll.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
+ this.btSellAll.Location = new System.Drawing.Point(574, 380);
+ this.btSellAll.Name = "btSellAll";
+ this.btSellAll.Size = new System.Drawing.Size(75, 23);
+ this.btSellAll.TabIndex = 2;
+ this.btSellAll.Text = "모두 청산";
+ this.btSellAll.UseVisualStyleBackColor = true;
+ this.btSellAll.Click += new System.EventHandler(this.btSellAll_Click);
+ //
+ // btSell
+ //
+ this.btSell.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
+ this.btSell.Location = new System.Drawing.Point(493, 380);
+ this.btSell.Name = "btSell";
+ this.btSell.Size = new System.Drawing.Size(75, 23);
+ this.btSell.TabIndex = 3;
+ this.btSell.Text = "매도";
+ this.btSell.UseVisualStyleBackColor = true;
+ this.btSell.Click += new System.EventHandler(this.btSell_Click);
+ //
+ // ULBalanceDlg
+ //
+ this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 12F);
+ this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+ this.ClientSize = new System.Drawing.Size(661, 415);
+ this.Controls.Add(this.btSell);
+ this.Controls.Add(this.btSellAll);
+ this.Controls.Add(this.btRefresh);
+ this.Controls.Add(this.lvBalance);
+ this.Name = "ULBalanceDlg";
+ this.Text = "잔고 평가";
+ this.ResumeLayout(false);
+
+ }
+
+ #endregion
+
+ private System.Windows.Forms.ListView lvBalance;
+ private System.Windows.Forms.ColumnHeader chName;
+ private System.Windows.Forms.ColumnHeader chCurPrice;
+ private System.Windows.Forms.ColumnHeader chBalance;
+ private System.Windows.Forms.ColumnHeader chUnitBEP;
+ private System.Windows.Forms.ColumnHeader chUnitProfit;
+ private System.Windows.Forms.ColumnHeader chProfitRate;
+ private System.Windows.Forms.Button btRefresh;
+ private System.Windows.Forms.ColumnHeader chCode;
+ private System.Windows.Forms.ColumnHeader chUnitBuyPrice;
+ private System.Windows.Forms.ColumnHeader chProfit;
+ private System.Windows.Forms.Button btSellAll;
+ private System.Windows.Forms.Button btSell;
+ }
+}
\ No newline at end of file
diff --git a/ULBalanceDlg.cs b/ULBalanceDlg.cs
new file mode 100644
index 0000000..12b27d2
--- /dev/null
+++ b/ULBalanceDlg.cs
@@ -0,0 +1,104 @@
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Data;
+using System.Drawing;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows.Forms;
+
+namespace upper_limit_crawler
+{
+ public partial class ULBalanceDlg : Form
+ {
+ ULDataMgr m_DataMgr = null;
+ CPTRADELib.CpTd6033 m_Td6033 = new CPTRADELib.CpTd6033();
+
+ public ULBalanceDlg(ULDataMgr DataMgr)
+ {
+ m_DataMgr = DataMgr;
+
+ InitializeComponent();
+ MainForm.SetDoubleBuffered(lvBalance);
+ btSell.Enabled = false;
+
+ RefreshData();
+ }
+
+ private void RefreshData()
+ {
+ m_Td6033.SetInputValue(0, m_DataMgr.GetAccount());
+ m_Td6033.SetInputValue(2, 50);
+
+ m_Td6033.BlockRequest2(0);
+
+ lvBalance.Items.Clear();
+
+ int iCnt = m_Td6033.GetHeaderValue(7);
+ for (int i = 0; i < iCnt; i++)
+ {
+ string strCodeName = m_Td6033.GetDataValue(0, i);
+ int iPayBalance = m_Td6033.GetDataValue(3, i); // 결제 잔고수량
+ int iPayUnitPrice = m_Td6033.GetDataValue(4, i); // 결제 장부단가
+ int iConclusionBalanceCnt = m_Td6033.GetDataValue(7, i); // 체결 잔고수량
+ long iEvaluationPrice = m_Td6033.GetDataValue(9, i); // 평가금액 : 보유수량x현재가
+ long iEvaluationProfit = m_Td6033.GetDataValue(10, i); // 평가손익
+ double dReturn = m_Td6033.GetDataValue(11, i); // 수익률
+ string strCode = m_Td6033.GetDataValue(12, i);
+ int iAskableCnt = m_Td6033.GetDataValue(15, i); // 매도 가능 수량
+ double dConclusionUnitPrice = m_Td6033.GetDataValue(17, i); // 체결 장부단가
+ long iUnitBEP = m_Td6033.GetDataValue(18, i); // 손익단가 : 수수료 포함 순익 분기점 Break-Even Point
+
+ int iCurPrice = (int)(iEvaluationPrice / iConclusionBalanceCnt);
+
+ string[] row = { strCode, strCodeName, dConclusionUnitPrice.ToString("###,###,##0"), iCurPrice.ToString("###,###,##0"), iConclusionBalanceCnt.ToString("###,###,##0"),
+ iUnitBEP.ToString("###,###,##0"), iEvaluationProfit.ToString("###,###,##0"), iEvaluationPrice.ToString("###,###,##0"), dReturn.ToString("#,##0.##")+"%" };
+ var listViewItem = new ListViewItem(row);
+ lvBalance.Items.Add(listViewItem);
+
+ UlUtil.Trace(string.Format("{0} {1} {2} {3} {4} {5} {6} {7} {8} {9} {10}",
+ strCodeName, iPayBalance, iPayUnitPrice,
+ iConclusionBalanceCnt, iEvaluationPrice, iEvaluationProfit,
+ dReturn, strCode, iAskableCnt, dConclusionUnitPrice, iUnitBEP));
+ }
+
+ foreach (ColumnHeader col in lvBalance.Columns)
+ col.Width = -2;
+ }
+
+ private void btRefresh_Click(object sender, EventArgs e)
+ {
+ RefreshData();
+ }
+
+ private void btSell_Click(object sender, EventArgs e)
+ {
+ foreach(ListViewItem item in lvBalance.SelectedItems)
+ {
+ string strCode = item.SubItems[chCode.Index].Text;
+ int iCnt = int.Parse(item.SubItems[chBalance.Index].Text);
+ m_DataMgr.GetTrader().SellCurPrice(strCode, iCnt);
+
+ UlUtil.Trace("");
+ }
+ }
+
+ private void btSellAll_Click(object sender, EventArgs e)
+ {
+ foreach (ListViewItem item in lvBalance.Items)
+ {
+ string strCode = item.SubItems[chCode.Index].Text;
+ int iCnt = int.Parse(item.SubItems[chBalance.Index].Text);
+ m_DataMgr.GetTrader().SellCurPrice(strCode, iCnt);
+
+ UlUtil.Trace("");
+ }
+ }
+
+ private void lvBalance_ItemSelectionChanged(object sender, ListViewItemSelectionChangedEventArgs e)
+ {
+ btSell.Enabled = (lvBalance.SelectedItems.Count > 0);
+ }
+ }
+}
diff --git a/ULBalanceDlg.resx b/ULBalanceDlg.resx
new file mode 100644
index 0000000..1af7de1
--- /dev/null
+++ b/ULBalanceDlg.resx
@@ -0,0 +1,120 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ text/microsoft-resx
+
+
+ 2.0
+
+
+ System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
\ No newline at end of file
diff --git a/ULDataMgr.cs b/ULDataMgr.cs
index 0c77d42..1edb106 100644
--- a/ULDataMgr.cs
+++ b/ULDataMgr.cs
@@ -8,7 +8,7 @@ using System.Threading.Tasks;
namespace upper_limit_crawler
{
- struct SETTING
+ public struct SETTING
{
public float m_fSearchMin;
public float m_fSearchMax;
@@ -20,7 +20,7 @@ namespace upper_limit_crawler
public float m_fLossCut;
}
- struct MONITOR_ITEM
+ public struct MONITOR_ITEM
{
public object Code;
public object Name;
@@ -35,12 +35,12 @@ namespace upper_limit_crawler
public object SerialDay;
}
- struct WATCH_ITEM
+ public struct WATCH_ITEM
{
public string m_strCode;
}
- class ULDataMgr
+ public class ULDataMgr
{
//MySqlConnection m_DBCon;
@@ -64,6 +64,11 @@ namespace upper_limit_crawler
//m_DBCon.Open();
}
+ public string GetAccount()
+ {
+ return m_Trader.GetAccount();
+ }
+
public ULTrader GetTrader()
{
return m_Trader;
diff --git a/ULMonitor.cs b/ULMonitor.cs
index 0e4763b..e6e9a9e 100644
--- a/ULMonitor.cs
+++ b/ULMonitor.cs
@@ -100,7 +100,7 @@ namespace upper_limit_crawler
m_DataMgr.IsInBlackList((string)Code) == false)
{
// bid and add to black list
- m_DataMgr.GetTrader().Buy((string)Code, (float)(int)CurPrice, m_DataMgr.m_Setting.m_fBidAmount);
+ m_DataMgr.GetTrader().Buy((string)Code, (int)CurPrice, (int)m_DataMgr.m_Setting.m_fBidAmount);
m_DataMgr.AddBlackList((string)Code);
}
@@ -129,7 +129,10 @@ namespace upper_limit_crawler
}
foreach (ColumnHeader col in lvWatch.Columns)
- col.AutoResize(ColumnHeaderAutoResizeStyle.HeaderSize);
+ {
+ col.Width = -2;
+ //col.AutoResize(ColumnHeaderAutoResizeStyle.HeaderSize);
+ }
m_bRequesting = false;
}
diff --git a/ULTrader.cs b/ULTrader.cs
index 35c3318..8d5841e 100644
--- a/ULTrader.cs
+++ b/ULTrader.cs
@@ -6,7 +6,7 @@ using System.Threading.Tasks;
namespace upper_limit_crawler
{
- class ULTrader
+ public class ULTrader
{
CPFORETRADELib.CpForeTdUtil m_Util = new CPFORETRADELib.CpForeTdUtil();
DSCBO1Lib.CpConclusion m_Conclusion = new DSCBO1Lib.CpConclusion();
@@ -23,6 +23,11 @@ namespace upper_limit_crawler
StartConclusion();
}
+ public string GetAccount()
+ {
+ return m_astrAccounts[0];
+ }
+
void StartConclusion()
{
m_Conclusion.Received += Conclusion_Received;
@@ -104,23 +109,23 @@ namespace upper_limit_crawler
// 80 시간외바스켓
// 79 시간외대량자기
- public void Buy(string strCode, long iBidPrice, long iBidAmount)
+ public void Buy(string strCode, int iUnitPrice, int iBidAmount)
{
- long iCnt = iBidAmount/iBidPrice;
+ int iCnt = iBidAmount/ iUnitPrice;
iCnt = 1;
m_Td0311Bid.SetInputValue(0, "2");
m_Td0311Bid.SetInputValue(1, m_astrAccounts[0]);
m_Td0311Bid.SetInputValue(3, strCode);
m_Td0311Bid.SetInputValue(4, iCnt); // 수량
- m_Td0311Bid.SetInputValue(5, iBidPrice); // 단가
+ m_Td0311Bid.SetInputValue(5, iUnitPrice); // 단가
m_Td0311Bid.SetInputValue(7, "0");
m_Td0311Bid.SetInputValue(8, "03");
m_Td0311Bid.BlockRequest();
}
- public void Sell(string strCode, long iAskPrice, long iCnt)
+ public void Sell(string strCode, int iUnitPrice, int iCnt)
{
//long iCnt = (long)Math.Floor(fAskAmount/fCurPrice);
//iCnt=1;
@@ -129,7 +134,23 @@ namespace upper_limit_crawler
m_Td0311Ask.SetInputValue(1, m_astrAccounts[0]);
m_Td0311Ask.SetInputValue(3, strCode);
m_Td0311Ask.SetInputValue(4, iCnt); // 수량
- m_Td0311Ask.SetInputValue(5, iAskPrice); // 단가
+ m_Td0311Ask.SetInputValue(5, iUnitPrice); // 단가
+ m_Td0311Ask.SetInputValue(7, "0");
+ m_Td0311Ask.SetInputValue(8, "03");
+
+ m_Td0311Ask.BlockRequest();
+ }
+
+ public void SellCurPrice(string strCode, int iCnt)
+ {
+ //long iCnt = (long)Math.Floor(fAskAmount/fCurPrice);
+ //iCnt=1;
+
+ m_Td0311Ask.SetInputValue(0, "1");
+ m_Td0311Ask.SetInputValue(1, m_astrAccounts[0]);
+ m_Td0311Ask.SetInputValue(3, strCode);
+ m_Td0311Ask.SetInputValue(4, iCnt); // 수량
+ m_Td0311Ask.SetInputValue(5, 0); // 단가
m_Td0311Ask.SetInputValue(7, "0");
m_Td0311Ask.SetInputValue(8, "03");
diff --git a/upper-limit-crawler.csproj b/upper-limit-crawler.csproj
index 06d08ff..4f24073 100644
--- a/upper-limit-crawler.csproj
+++ b/upper-limit-crawler.csproj
@@ -57,6 +57,12 @@
+
+ Form
+
+
+ ULBalanceDlg.cs
+
Form
@@ -85,6 +91,9 @@
ULWatchForm.cs
+
+ ULBalanceDlg.cs
+
MainForm.cs