diff --git a/.gitignore b/.gitignore index efdf9d8..894080e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ bin/ obj/ -*.suo \ No newline at end of file +*.suo +log/ diff --git a/MainForm.Designer.cs b/MainForm.Designer.cs index d0fbf38..62e11fc 100644 --- a/MainForm.Designer.cs +++ b/MainForm.Designer.cs @@ -51,6 +51,8 @@ this.splitContainer1 = new System.Windows.Forms.SplitContainer(); this.splitContainer2 = new System.Windows.Forms.SplitContainer(); this.splitContainer3 = new System.Windows.Forms.SplitContainer(); + this.lbSBCnt = new System.Windows.Forms.Label(); + this.lbRQCnt = new System.Windows.Forms.Label(); ((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).BeginInit(); this.splitContainer1.Panel1.SuspendLayout(); this.splitContainer1.Panel2.SuspendLayout(); @@ -102,7 +104,7 @@ this.tbBidAmount.Name = "tbBidAmount"; this.tbBidAmount.Size = new System.Drawing.Size(100, 21); this.tbBidAmount.TabIndex = 9; - this.tbBidAmount.Text = "1,000,000"; + this.tbBidAmount.Text = "100,000"; this.tbBidAmount.TextAlign = System.Windows.Forms.HorizontalAlignment.Center; // // tbTimeout @@ -201,7 +203,7 @@ this.tbSearchMin.Name = "tbSearchMin"; this.tbSearchMin.Size = new System.Drawing.Size(37, 21); this.tbSearchMin.TabIndex = 14; - this.tbSearchMin.Text = "9.0%"; + this.tbSearchMin.Text = "7.0%"; this.tbSearchMin.TextAlign = System.Windows.Forms.HorizontalAlignment.Center; // // btApply @@ -281,6 +283,8 @@ // // splitContainer2.Panel2 // + this.splitContainer2.Panel2.Controls.Add(this.lbSBCnt); + this.splitContainer2.Panel2.Controls.Add(this.lbRQCnt); this.splitContainer2.Panel2.Controls.Add(this.btBalance); this.splitContainer2.Panel2.Controls.Add(this.label1); this.splitContainer2.Panel2.Controls.Add(this.label5); @@ -314,6 +318,24 @@ this.splitContainer3.SplitterDistance = 231; this.splitContainer3.TabIndex = 0; // + // lbSBCnt + // + this.lbSBCnt.AutoSize = true; + this.lbSBCnt.Location = new System.Drawing.Point(29, 278); + this.lbSBCnt.Name = "lbSBCnt"; + this.lbSBCnt.Size = new System.Drawing.Size(70, 12); + this.lbSBCnt.TabIndex = 19; + this.lbSBCnt.Text = "SB Count : "; + // + // lbRQCnt + // + this.lbRQCnt.AutoSize = true; + this.lbRQCnt.Location = new System.Drawing.Point(29, 254); + this.lbRQCnt.Name = "lbRQCnt"; + this.lbRQCnt.Size = new System.Drawing.Size(71, 12); + this.lbRQCnt.TabIndex = 18; + this.lbRQCnt.Text = "RQ Count : "; + // // MainForm // this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 12F); @@ -321,7 +343,7 @@ this.ClientSize = new System.Drawing.Size(886, 642); this.Controls.Add(this.splitContainer1); this.Name = "MainForm"; - this.Text = "Form1"; + this.Text = "Upper Limit"; this.splitContainer1.Panel1.ResumeLayout(false); this.splitContainer1.Panel2.ResumeLayout(false); this.splitContainer1.Panel2.PerformLayout(); @@ -362,6 +384,8 @@ private System.Windows.Forms.SplitContainer splitContainer1; private System.Windows.Forms.SplitContainer splitContainer2; private System.Windows.Forms.SplitContainer splitContainer3; - } + private System.Windows.Forms.Label lbRQCnt; + private System.Windows.Forms.Label lbSBCnt; + } } diff --git a/MainForm.cs b/MainForm.cs index 5439f34..8f497b6 100644 --- a/MainForm.cs +++ b/MainForm.cs @@ -25,8 +25,6 @@ namespace upper_limit_crawler int m_iLastTime = 0; static ULDataMgr m_DataMgr = new ULDataMgr(); - ULWatch m_Watch = new ULWatch(m_DataMgr); - ULDealing m_Dealing = new ULDealing(m_DataMgr); ULOwn m_Own = new ULOwn(m_DataMgr); ULMonitorDlg m_MonitorDlg = null; @@ -35,7 +33,10 @@ namespace upper_limit_crawler public MainForm() { InitializeComponent(); - //UlUtil.SetLogView(tbLog); + + SetDoubleBuffered(tbLog); + + UlUtil.Init(tbLog); btApply_Click(null, null); @@ -96,10 +97,11 @@ namespace upper_limit_crawler int iDeltaT = iCurTime - m_iLastTime; - m_Watch.Refresh(iCurTime); - m_Dealing.Refresh(iCurTime); m_Own.Refresh(iCurTime); + lbRQCnt.Text = "RQ Count : " + UlUtil.GetLimitRemainCountRQ().ToString(); + lbSBCnt.Text = "SB Count : " + UlUtil.GetLimitRemainCountSB().ToString(); + m_iLastTime = iCurTime; } @@ -115,10 +117,10 @@ namespace upper_limit_crawler { try { - m_DataMgr.m_Setting.m_fSearchMin = float.Parse(tbSearchMin.Text.Replace("%", "")); - m_DataMgr.m_Setting.m_fSearchMax = float.Parse(tbSearchMax.Text.Replace("%", "")); - m_DataMgr.m_Setting.m_fBidMin = float.Parse(tbBidMin.Text.Replace("%", "")); - m_DataMgr.m_Setting.m_fBidMax = float.Parse(tbBidMax.Text.Replace("%", "")); + m_DataMgr.m_Setting.m_fSearchMin = float.Parse(tbSearchMin.Text.Replace("%", ""))/100; + m_DataMgr.m_Setting.m_fSearchMax = float.Parse(tbSearchMax.Text.Replace("%", ""))/100; + m_DataMgr.m_Setting.m_fBidMin = float.Parse(tbBidMin.Text.Replace("%", ""))/100; + m_DataMgr.m_Setting.m_fBidMax = float.Parse(tbBidMax.Text.Replace("%", ""))/100; m_DataMgr.m_Setting.m_fBidAmount = float.Parse(tbBidAmount.Text); m_DataMgr.m_Setting.m_fTimeout = float.Parse(tbTimeout.Text); m_DataMgr.m_Setting.m_fTrailing = float.Parse(tbTrailing.Text.Replace("%", ""))/100; @@ -134,14 +136,14 @@ namespace upper_limit_crawler private void btCancel_Click(object sender, EventArgs e) { - tbSearchMin.Text = m_DataMgr.m_Setting.m_fSearchMin.ToString("0.0")+"%"; - tbSearchMax.Text = m_DataMgr.m_Setting.m_fSearchMax.ToString("0.0") + "%"; - tbBidMin.Text = m_DataMgr.m_Setting.m_fBidMin.ToString("0.0") + "%"; - tbBidMax.Text = m_DataMgr.m_Setting.m_fBidMax.ToString("0.0") + "%"; + tbSearchMin.Text = (m_DataMgr.m_Setting.m_fSearchMin*100).ToString("0.0") + "%"; + tbSearchMax.Text = (m_DataMgr.m_Setting.m_fSearchMax*100).ToString("0.0") + "%"; + tbBidMin.Text = (m_DataMgr.m_Setting.m_fBidMin*100).ToString("0.0") + "%"; + tbBidMax.Text = (m_DataMgr.m_Setting.m_fBidMax*100).ToString("0.0") + "%"; tbBidAmount.Text = m_DataMgr.m_Setting.m_fBidAmount.ToString("###,###,###,###,###"); tbTimeout.Text = m_DataMgr.m_Setting.m_fTimeout.ToString("0.###"); - tbTrailing.Text = m_DataMgr.m_Setting.m_fTrailing.ToString("0.0%"); - tbLossCut.Text = m_DataMgr.m_Setting.m_fLossCut.ToString("0.0%"); + tbTrailing.Text = (m_DataMgr.m_Setting.m_fTrailing*100).ToString("0.0") + "%"; + tbLossCut.Text = (m_DataMgr.m_Setting.m_fLossCut*100).ToString("0.0") + "%"; } } } diff --git a/ULBalanceDlg.Designer.cs b/ULBalanceDlg.Designer.cs index 7f4e7d3..aeacf4a 100644 --- a/ULBalanceDlg.Designer.cs +++ b/ULBalanceDlg.Designer.cs @@ -34,7 +34,7 @@ this.chUnitBuyPrice = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); this.chUnitBEP = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); this.chCurPrice = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); - this.chUnitProfit = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); + this.chEvaluationProfit = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); this.chBalance = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); this.chEvaluationPrice = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); this.chProfitRate = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); @@ -54,7 +54,7 @@ this.chUnitBuyPrice, this.chUnitBEP, this.chCurPrice, - this.chUnitProfit, + this.chEvaluationProfit, this.chBalance, this.chEvaluationPrice, this.chProfitRate}); @@ -93,10 +93,10 @@ this.chCurPrice.Text = "현재가"; this.chCurPrice.TextAlign = System.Windows.Forms.HorizontalAlignment.Right; // - // chUnitProfit + // chEvaluationProfit // - this.chUnitProfit.Text = "평가손익"; - this.chUnitProfit.TextAlign = System.Windows.Forms.HorizontalAlignment.Right; + this.chEvaluationProfit.Text = "평가손익"; + this.chEvaluationProfit.TextAlign = System.Windows.Forms.HorizontalAlignment.Right; // // chBalance // @@ -171,7 +171,7 @@ 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 chEvaluationProfit; private System.Windows.Forms.ColumnHeader chProfitRate; private System.Windows.Forms.Button btRefresh; private System.Windows.Forms.ColumnHeader chCode; diff --git a/ULBalanceDlg.cs b/ULBalanceDlg.cs index 3f70826..e7996ed 100644 --- a/ULBalanceDlg.cs +++ b/ULBalanceDlg.cs @@ -5,6 +5,7 @@ using System.Data; using System.Drawing; using System.Linq; using System.Text; +using System.Text.RegularExpressions; using System.Threading.Tasks; using System.Windows.Forms; @@ -13,7 +14,6 @@ namespace upper_limit_crawler public partial class ULBalanceDlg : Form { const int BALANCE_DELAY = 10000; - const int PRICE_DELAY = 500; public class OWN_ITEM { @@ -23,7 +23,7 @@ namespace upper_limit_crawler public int m_iConclusionBalanceCnt; public long m_iEvaluationPrice; public long m_iEvaluationProfit; - public double m_dReturn; + public double m_dProfitRate; public string m_strCode; public int m_iAskableCnt; public double m_dConclusionUnitPrice; @@ -42,18 +42,18 @@ namespace upper_limit_crawler Timer m_MainTimer = new Timer(); int m_iLastTime = 0; int m_iBalanceDelay = BALANCE_DELAY; - int m_iPriceDelay = PRICE_DELAY; ULDataMgr m_DataMgr = null; CPTRADELib.CpTd6033 m_Td6033 = new CPTRADELib.CpTd6033(); - - bool m_bRequesting = false; + DSCBO1Lib.StockCur m_StockCur = new DSCBO1Lib.StockCur(); public ULBalanceDlg(ULDataMgr DataMgr) { InitializeComponent(); + MainForm.SetDoubleBuffered(lvBalance); + this.TopLevel = false; m_DataMgr = DataMgr; @@ -83,58 +83,60 @@ namespace upper_limit_crawler int iCnt = m_Td6033.GetHeaderValue(7); for(int i = 0; i itemFind.m_strCode == strCode); - if (item == null) + m_DataMgr.AddWatch(strCode, strCodeName, iCurPrice, iCurPrice); + + OWN_ITEM OwnItem = m_OwnList.Find(itemFind => itemFind.m_strCode == strCode); + if (OwnItem == null) { - item = new OWN_ITEM(); - m_OwnList.Add(item); + OwnItem = new OWN_ITEM(); + m_OwnList.Add(OwnItem); } - item.m_strCodeName = strCodeName; - item.m_iPayBalance = iPayBalance; - item.m_iPayUnitPrice = iPayUnitPrice; - item.m_iConclusionBalanceCnt = iConclusionBalanceCnt; - item.m_iEvaluationPrice = iEvaluationPrice; - item.m_iEvaluationProfit = iEvaluationProfit; - item.m_dReturn = dReturn; - item.m_strCode = strCode; - item.m_iAskableCnt = iAskableCnt; - item.m_dConclusionUnitPrice = dConclusionUnitPrice; - item.m_iUnitBEP = iUnitBEP; - item.m_iCurPrice = iCurPrice; - item.m_iMaxPrice = iCurPrice; - item.m_bCheck = true; - + OwnItem.m_strCodeName = strCodeName; + OwnItem.m_iPayBalance = iPayBalance; + OwnItem.m_iPayUnitPrice = iPayUnitPrice; + OwnItem.m_iConclusionBalanceCnt = iConclusionBalanceCnt; + OwnItem.m_iEvaluationPrice = iEvaluationPrice; + OwnItem.m_iEvaluationProfit = iEvaluationProfit; + OwnItem.m_dProfitRate = dReturn; + OwnItem.m_strCode = strCode; + OwnItem.m_iAskableCnt = iAskableCnt; + OwnItem.m_dConclusionUnitPrice = dConclusionUnitPrice; + OwnItem.m_iUnitBEP = iUnitBEP; + OwnItem.m_iCurPrice = iCurPrice; + OwnItem.m_iMaxPrice = iCurPrice; + OwnItem.m_bCheck = true; - string[] row = { strCode, strCodeName, dConclusionUnitPrice.ToString("###,###,##0"), + ListViewItem listViewItem = new ListViewItem(new string[] { strCode, strCodeName, dConclusionUnitPrice.ToString("###,###,##0"), iUnitBEP.ToString("###,###,##0"), iCurPrice.ToString("###,###,##0"), - iEvaluationProfit.ToString("###,###,##0"), iConclusionBalanceCnt.ToString("###,###,##0"), - iEvaluationPrice.ToString("###,###,##0"), dReturn.ToString("#,##0.00")+"%" }; - ListViewItem listViewItem = new ListViewItem(row); + iEvaluationProfit.ToString("###,###,##0"), iConclusionBalanceCnt.ToString("###,###,##0"), + iEvaluationPrice.ToString("###,###,##0"), dReturn.ToString("#,##0.00")+"%" }); listViewItem.UseItemStyleForSubItems = false; + + if(iEvaluationProfit > 0) + listViewItem.SubItems[chEvaluationProfit.Index].ForeColor = Color.Red; + else + listViewItem.SubItems[chEvaluationProfit.Index].ForeColor = Color.Blue; + if (dReturn > 0) listViewItem.SubItems[chProfitRate.Index].ForeColor = Color.Red; else if (dReturn < 0) listViewItem.SubItems[chProfitRate.Index].ForeColor = Color.Blue; - 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)); + lvBalance.Items.Add(listViewItem); } m_OwnList.RemoveAll(c => c.m_bCheck = false); @@ -145,59 +147,64 @@ namespace upper_limit_crawler private void RefreshCurPrice() { - if (m_bRequesting == true) - return; - m_bRequesting = true; - - if (m_OwnList.Count <= 0) - return; - - string strPriceList = ""; - foreach(OWN_ITEM item in m_OwnList) + Dictionary WatchList = m_DataMgr.GetWatchList(); + foreach (ListViewItem lvItem in lvBalance.Items) { - if (strPriceList.Length > 0) - strPriceList += ","; - strPriceList += item.m_strCode; - } - - - m_StockMst2.SetInputValue(0, strPriceList); - m_StockMst2.BlockRequest2(1); - - int iCnt = m_StockMst2.GetHeaderValue(0); - for(int i=0; i item.m_strCode == strCode); - if (listItem == null) - continue; - - listItem.m_iCurPrice = iCurPrice; - listItem.m_iMaxPrice = Math.Max(iCurPrice, listItem.m_iMaxPrice); - - ListViewItem lvItem = lvBalance.FindItemWithText(strCode); - if (lvItem != null) + string strCode = lvItem.SubItems[chCode.Index].Text; + if (WatchList.ContainsKey(strCode) == true) { - lvItem.SubItems[chCurPrice.Index].Text = iCurPrice.ToString("###,###,##0"); - lvItem.SubItems[chUnitProfit.Index].Text = (iCurPrice - listItem.m_iUnitBEP).ToString("###,###,##0"); - lvItem.SubItems[chEvaluationPrice.Index].Text = (iCurPrice*listItem.m_iConclusionBalanceCnt).ToString("###,###,##0"); - lvItem.SubItems[chProfitRate.Index].Text = (iCurPrice / (float)listItem.m_iUnitBEP - 1.0f).ToString("#,##0.00%"); - } + WATCH_ITEM WatchItem = WatchList[strCode]; + OWN_ITEM OwnItem = m_OwnList.Find(itemFind => itemFind.m_strCode == strCode); + int iDisplayCurPrice = 0; + if (lvItem.SubItems[chCurPrice.Index].Text.Length > 0) + iDisplayCurPrice = int.Parse(Regex.Replace(lvItem.SubItems[chCurPrice.Index].Text, @"\D", "")); - // cut loss and trailing - if (iCurPrice <= listItem.m_iUnitBEP * (1.0f - m_DataMgr.m_Setting.m_fLossCut) || - iCurPrice <= listItem.m_iMaxPrice * (1.0f - m_DataMgr.m_Setting.m_fTrailing)) - { - m_DataMgr.GetTrader().SellCurPrice(listItem.m_strCode, listItem.m_iPayBalance); - - // 미체결 잔량 취소 + if (WatchItem.m_iCurPrice != iDisplayCurPrice && iDisplayCurPrice != 0) + { + int iCurPrice = WatchItem.m_iCurPrice; + int iComp = iCurPrice - (int)OwnItem.m_iUnitBEP; // or OwnItem.m_dConclusionUnitPrice + + OwnItem.m_iCurPrice = iCurPrice; + OwnItem.m_iEvaluationPrice = iCurPrice * OwnItem.m_iConclusionBalanceCnt; + OwnItem.m_iEvaluationProfit = iComp * OwnItem.m_iConclusionBalanceCnt; + OwnItem.m_dProfitRate = iComp / (float)OwnItem.m_iUnitBEP; + + lvItem.SubItems[chCurPrice.Index].Text = iCurPrice.ToString("###,###,##0"); + lvItem.SubItems[chEvaluationPrice.Index].Text = OwnItem.m_iEvaluationPrice.ToString("###,###,##0"); + lvItem.SubItems[chEvaluationProfit.Index].Text = OwnItem.m_iEvaluationProfit.ToString("###,###,##0"); + if (OwnItem.m_iEvaluationProfit > 0) + lvItem.SubItems[chEvaluationProfit.Index].ForeColor = Color.Red; + else + lvItem.SubItems[chEvaluationProfit.Index].ForeColor = Color.Blue; + lvItem.SubItems[chEvaluationPrice.Index].Text = OwnItem.m_iEvaluationPrice.ToString("###,###,##0"); + lvItem.SubItems[chProfitRate.Index].Text = OwnItem.m_dProfitRate.ToString("#,##0.00")+"%"; + if (OwnItem.m_dProfitRate > 0) + lvItem.SubItems[chProfitRate.Index].ForeColor = Color.Red; + else + lvItem.SubItems[chProfitRate.Index].ForeColor = Color.Blue; + + + OwnItem.m_iMaxPrice = Math.Max(iCurPrice, OwnItem.m_iMaxPrice); + + // loss cut + if (iCurPrice <= OwnItem.m_iUnitBEP * (1.0f - m_DataMgr.m_Setting.m_fLossCut)) + { + UlUtil.Trace(string.Format("[{0}] 손절({1})", OwnItem.m_strCodeName, iCurPrice)); + m_DataMgr.GetTrader().SellCurPrice(OwnItem.m_strCode, OwnItem.m_iPayBalance); + m_OwnList.Remove(OwnItem); + + // 미체결 잔량 취소 + } + // trailing + else if (iCurPrice <= OwnItem.m_iMaxPrice - OwnItem.m_iUnitBEP * m_DataMgr.m_Setting.m_fTrailing) + { + UlUtil.Trace(string.Format("[{0}] 트레일링 매도({1})", OwnItem.m_strCodeName, iCurPrice)); + m_DataMgr.GetTrader().SellCurPrice(OwnItem.m_strCode, OwnItem.m_iPayBalance); + m_OwnList.Remove(OwnItem); + } + } } } - - m_bRequesting = false; } private void RefreshData(object sender, EventArgs e) @@ -217,13 +224,7 @@ namespace upper_limit_crawler m_iBalanceDelay=BALANCE_DELAY; } - m_iPriceDelay -= iDeltaT; - if(m_iPriceDelay<= 0 && UlUtil.GetLimitRemainCountRQ() >= m_OwnList.Count) - { - RefreshCurPrice(); - m_iPriceDelay = PRICE_DELAY; - } - + RefreshCurPrice(); m_iLastTime=iCurTime; } @@ -237,11 +238,11 @@ namespace upper_limit_crawler { foreach(ListViewItem item in lvBalance.SelectedItems) { + UlUtil.Trace(string.Format("[{0}] 수동 매도", item.SubItems[chName.Index].Text)); + string strCode = item.SubItems[chCode.Index].Text; int iCnt = int.Parse(item.SubItems[chBalance.Index].Text); m_DataMgr.GetTrader().SellCurPrice(strCode, iCnt); - - UlUtil.Trace(""); } } @@ -249,11 +250,11 @@ namespace upper_limit_crawler { foreach (ListViewItem item in lvBalance.Items) { + UlUtil.Trace(string.Format("[{0}] 모두 청산", item.SubItems[chName.Index].Text)); + string strCode = item.SubItems[chCode.Index].Text; int iCnt = int.Parse(item.SubItems[chBalance.Index].Text); m_DataMgr.GetTrader().SellCurPrice(strCode, iCnt); - - UlUtil.Trace(""); } } diff --git a/ULDataMgr.cs b/ULDataMgr.cs index 0346b59..620306c 100644 --- a/ULDataMgr.cs +++ b/ULDataMgr.cs @@ -20,24 +20,10 @@ namespace upper_limit_crawler public float m_fLossCut; } - public struct MONITOR_ITEM - { - public string Code; - public string Name; - public int CurPrice; - public object flag; - public int Comp; - public float CompRate; - public int Volume; - public int StartPrice; - public int StartPriceComp; - public float StartPriceCompRate; - public int SerialDay; - } - public class WATCH_ITEM { public string m_strCode; + public string m_strCodeName; public DSCBO1Lib.StockCur m_StockCur = null; public int m_iCurPrice; @@ -56,7 +42,6 @@ namespace upper_limit_crawler ULTrader m_Trader = new ULTrader(); - List m_MonitorList = new List(); Dictionary m_WatchList = new Dictionary(); List m_BlackList = new List(); @@ -75,23 +60,14 @@ namespace upper_limit_crawler return m_Trader; } - public void ClearMonitor() - { - m_MonitorList.Clear(); - } - - public void AddMonitor(MONITOR_ITEM Item) - { - m_MonitorList.Add(Item); - } - - public void AddWatch(string strCode, int iCurPrice, int iPrevClosing) + public void AddWatch(string strCode, string strCodeName, int iCurPrice, int iPrevClosing) { if (m_WatchList.ContainsKey(strCode)) return; WATCH_ITEM item = new WATCH_ITEM(); item.m_strCode = strCode; + item.m_strCodeName = strCodeName; item.m_iCurPrice = iCurPrice; item.m_iPrevClosing = iPrevClosing; @@ -108,6 +84,7 @@ namespace upper_limit_crawler foreach(KeyValuePair item in m_WatchList) { item.Value.m_iCurPrice = item.Value.m_StockCur.GetHeaderValue(13); + item.Value.m_iPrevClosing = item.Value.m_StockCur.GetHeaderValue(2); item.Value.m_iStartPrice = item.Value.m_StockCur.GetHeaderValue(4); item.Value.m_iHighestPrice = item.Value.m_StockCur.GetHeaderValue(5); item.Value.m_iVolume = item.Value.m_StockCur.GetHeaderValue(9); @@ -126,11 +103,6 @@ namespace upper_limit_crawler return m_BlackList.Contains(strCode); } - public List GetMonitor() - { - return m_MonitorList; - } - public Dictionary GetWatchList() { return m_WatchList; diff --git a/ULDealing.cs b/ULDealing.cs deleted file mode 100644 index 74c79ba..0000000 --- a/ULDealing.cs +++ /dev/null @@ -1,27 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace upper_limit_crawler -{ - class ULDealing : ULObj - { - public ULDealing(ULDataMgr DataMgr) : base(DataMgr) - { - - } - - public override void Refresh(int iCurTime) - { - if(m_iLastTime == 0) - { - base.Refresh(iCurTime); - return; - } - - base.Refresh(iCurTime); - } - } -} diff --git a/ULMonitorDlg.Designer.cs b/ULMonitorDlg.Designer.cs new file mode 100644 index 0000000..127ef58 --- /dev/null +++ b/ULMonitorDlg.Designer.cs @@ -0,0 +1,136 @@ +namespace upper_limit_crawler +{ + partial class ULMonitorDlg + { + /// + /// 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.lvWatch = new System.Windows.Forms.ListView(); + this.chOrder = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); + this.chCode = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); + this.chName = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); + this.chCurPrice = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); + this.chComp = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); + this.chCompRate = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); + this.chVolume = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); + this.chBidPrice = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); + this.chBidCnt = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); + this.SuspendLayout(); + // + // lvWatch + // + this.lvWatch.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.lvWatch.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] { + this.chOrder, + this.chCode, + this.chName, + this.chCurPrice, + this.chComp, + this.chCompRate, + this.chVolume, + this.chBidPrice, + this.chBidCnt}); + 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(826, 296); + this.lvWatch.TabIndex = 5; + this.lvWatch.UseCompatibleStateImageBehavior = false; + this.lvWatch.View = System.Windows.Forms.View.Details; + // + // chOrder + // + this.chOrder.Text = "순위"; + // + // chCode + // + this.chCode.Text = "종목코드"; + // + // chName + // + this.chName.Text = "종목명"; + // + // chCurPrice + // + this.chCurPrice.Text = "현재가"; + this.chCurPrice.TextAlign = System.Windows.Forms.HorizontalAlignment.Right; + // + // chComp + // + this.chComp.Text = "전일대비"; + this.chComp.TextAlign = System.Windows.Forms.HorizontalAlignment.Right; + // + // chCompRate + // + this.chCompRate.Text = "대비율"; + this.chCompRate.TextAlign = System.Windows.Forms.HorizontalAlignment.Right; + // + // chVolume + // + this.chVolume.Text = "거래량"; + this.chVolume.TextAlign = System.Windows.Forms.HorizontalAlignment.Right; + // + // chBidPrice + // + this.chBidPrice.Text = "매수호가"; + this.chBidPrice.TextAlign = System.Windows.Forms.HorizontalAlignment.Right; + // + // chBidCnt + // + this.chBidCnt.Text = "호가잔량"; + this.chBidCnt.TextAlign = System.Windows.Forms.HorizontalAlignment.Right; + // + // ULMonitorDlg + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 12F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(850, 320); + this.Controls.Add(this.lvWatch); + this.DoubleBuffered = true; + this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None; + this.Name = "ULMonitorDlg"; + this.Text = "ULMonitorDlg"; + this.ResumeLayout(false); + + } + + #endregion + + private System.Windows.Forms.ListView lvWatch; + private System.Windows.Forms.ColumnHeader chOrder; + private System.Windows.Forms.ColumnHeader chName; + private System.Windows.Forms.ColumnHeader chCurPrice; + private System.Windows.Forms.ColumnHeader chComp; + private System.Windows.Forms.ColumnHeader chCompRate; + private System.Windows.Forms.ColumnHeader chVolume; + private System.Windows.Forms.ColumnHeader chBidPrice; + private System.Windows.Forms.ColumnHeader chBidCnt; + private System.Windows.Forms.ColumnHeader chCode; + } +} \ No newline at end of file diff --git a/ULMonitorDlg.cs b/ULMonitorDlg.cs new file mode 100644 index 0000000..883756d --- /dev/null +++ b/ULMonitorDlg.cs @@ -0,0 +1,192 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Text.RegularExpressions; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace upper_limit_crawler +{ + public partial class ULMonitorDlg : Form + { + const int MONITOR_DELAY = 1500; + + ULDataMgr m_DataMgr; + CPSYSDIBLib.CpSvrNew7043 m_7043 = new CPSYSDIBLib.CpSvrNew7043(); + Timer m_Timer = new Timer(); + int m_iMonitorDelay = 0; + int m_iLastTime = 0; + bool m_bRequesting = false; + + DSCBO1Lib.StockCur m_StockCur = new DSCBO1Lib.StockCur(); + + public ULMonitorDlg(ULDataMgr DataMgr) + { + InitializeComponent(); + + MainForm.SetDoubleBuffered(lvWatch); + + this.TopLevel = false; + + m_DataMgr = DataMgr; + + m_7043.SetInputValue(0, '0'); + m_7043.SetInputValue(1, '2'); + m_7043.SetInputValue(2, '1'); + m_7043.SetInputValue(3, 21); + m_7043.SetInputValue(4, '1'); + m_7043.SetInputValue(5, '0'); + m_7043.SetInputValue(6, '0'); + m_7043.SetInputValue(7, (short)(m_DataMgr.m_Setting.m_fSearchMin*100)); + m_7043.SetInputValue(8, (short)((m_DataMgr.m_Setting.m_fSearchMax+0.009)*100)); + + m_StockCur.Received += StockCur_Received; + + m_Timer.Interval = 100; + m_Timer.Tick += Refresh; + m_Timer.Start(); + } + + private void StockCur_Received() + { + + } + + bool Check() + { + if (m_bRequesting == true || UlUtil.GetLimitRemainCountRQ() < 30) + return false; + + m_bRequesting = true; + m_7043.SetInputValue(7, (short)(m_DataMgr.m_Setting.m_fSearchMin * 100)); + m_7043.SetInputValue(8, (short)((m_DataMgr.m_Setting.m_fSearchMax + 0.009) * 100)); + int iResult = m_7043.BlockRequest2(1); + + lvWatch.Items.Clear(); + int iIdx = 1; + + bool bContinue = true; + while (bContinue) + { + int iCnt = m_7043.GetHeaderValue(0); + for (int i = 0; i < iCnt; i++) + { + string strCode = m_7043.GetDataValue(0, i); + string strCodeName = m_7043.GetDataValue(1, i); + int iCurPrice = m_7043.GetDataValue(2, i); + object flag = m_7043.GetDataValue(3, i); + int iComp = m_7043.GetDataValue(4, i); + float fCompRate = m_7043.GetDataValue(5, i); + int iVolume = m_7043.GetDataValue(6, i); + int iStartPrice = m_7043.GetDataValue(7, i); + int iStartPriceComp = m_7043.GetDataValue(8, i); + float fStartPriceCompRate = m_7043.GetDataValue(9, i); + int iSerialDay = m_7043.GetDataValue(10, i); + + ListViewItem searchItem = null; + if(lvWatch.Items.Count > 0) + searchItem = lvWatch.FindItemWithText(strCode, true, 0, false); + + if(searchItem != null) + { + searchItem.SubItems[chOrder.Index].Text = iIdx.ToString(); + searchItem.SubItems[chCurPrice.Index].Text = iCurPrice.ToString("###,###,###,###"); + searchItem.SubItems[chComp.Index].Text = iComp.ToString("###,###,###,###"); + searchItem.SubItems[chCompRate.Index].Text = fCompRate.ToString("#,##0.00"); + searchItem.SubItems[chVolume.Index].Text = iVolume.ToString("###,###,###,###"); + } + else + { + ListViewItem listViewItem = new ListViewItem(new string[] { iIdx.ToString(), strCode.ToString(), strCodeName.ToString(), + iCurPrice.ToString("###,###,###,###"), iComp.ToString("###,###,###,###"), fCompRate.ToString("#,##0.00")+"%", + iVolume.ToString("###,###,###,###"), 0.ToString(), 0.ToString() }); + lvWatch.Items.Add(listViewItem); + } + + iIdx++; + + if (fCompRate >= m_DataMgr.m_Setting.m_fSearchMin * 100 && fCompRate <= m_DataMgr.m_Setting.m_fSearchMax * 100) + { + m_DataMgr.AddWatch(strCode, strCodeName, iCurPrice, iStartPrice); + } + } + + bContinue = (m_7043.Continue == 1); + if (bContinue == true && UlUtil.GetLimitRemainCountRQ() >= 30) + iResult = m_7043.BlockRequest2(1); + } + + //foreach (ColumnHeader col in lvWatch.Columns) + // col.Width = -2; + + m_bRequesting = false; + return true; + } + + void RefreshData() + { + Dictionary WatchList = m_DataMgr.GetWatchList(); + foreach (ListViewItem lvItem in lvWatch.Items) + { + string strCode = lvItem.SubItems[chCode.Index].Text; + if (WatchList.ContainsKey(strCode) == true) + { + WATCH_ITEM item = WatchList[strCode]; + + int iDisplayCurPrice = 0; + if (lvItem.SubItems[chCurPrice.Index].Text.Length > 0) + iDisplayCurPrice = int.Parse(Regex.Replace(lvItem.SubItems[chCurPrice.Index].Text, @"\D", "")); + + if (item.m_iCurPrice != iDisplayCurPrice && item.m_iCurPrice != 0) + { + int iComp = item.m_iCurPrice - item.m_iPrevClosing; + float fCompRate = item.m_iCurPrice / (float)item.m_iPrevClosing - 1.0f; + + lvItem.SubItems[chCurPrice.Index].Text = item.m_iCurPrice.ToString("###,###,###,###"); + lvItem.SubItems[chComp.Index].Text = iComp.ToString("###,###,###,###"); + lvItem.SubItems[chCompRate.Index].Text = fCompRate.ToString("#,##0.00%") + "%"; + lvItem.SubItems[chVolume.Index].Text = item.m_iVolume.ToString("###,###,###,###"); + lvItem.SubItems[chBidPrice.Index].Text = item.m_iBidPrice.ToString("###,###,###,###"); + + if (fCompRate >= m_DataMgr.m_Setting.m_fBidMin && + fCompRate <= m_DataMgr.m_Setting.m_fBidMax && + m_DataMgr.IsInBlackList(strCode) == false) + { + // bid and add to black list + UlUtil.Trace(string.Format("[{0}] 조건 매수 {1}원 ({2})", item.m_strCodeName, item.m_iCurPrice, fCompRate)); + + m_DataMgr.GetTrader().Buy(strCode, item.m_iCurPrice, (int)m_DataMgr.m_Setting.m_fBidAmount); + m_DataMgr.AddBlackList(strCode); + } + } + } + } + } + + private void Refresh(object sender, EventArgs e) + { + int iCurTime = Environment.TickCount; + if (m_iLastTime == 0) + { + m_iLastTime = iCurTime; + return; + } + + int iDeltaT = iCurTime - m_iLastTime; + m_iMonitorDelay -= iDeltaT; + if (m_iMonitorDelay <= 0) + { + bool bRequest = Check(); + m_iMonitorDelay = (bRequest == true) ? MONITOR_DELAY : 1000; + } + + RefreshData(); + + m_iLastTime = iCurTime; + } + } +} diff --git a/ULMonitorDlg.resx b/ULMonitorDlg.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/ULMonitorDlg.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/ULTrader.cs b/ULTrader.cs index a6d7083..d848d1b 100644 --- a/ULTrader.cs +++ b/ULTrader.cs @@ -53,6 +53,20 @@ namespace upper_limit_crawler string strLog = ""; + if (strTradeType == "1") // 정상주문 + { strLog += "[정상주문]"; } + else if (strTradeType == "2") // 정정주문 + { strLog += "[정정주문]"; } + else if (strTradeType == "3") // 취소주문 + { strLog += "[취소주문]"; } + + if (bBuy == true) + strLog += "(매수) "; + else + strLog += "(매도) "; + + strLog += string.Format("[{0}:{1}] {2:###,###,##0}원 {3:###,###,##0}주 (총{4:###,###,##0}원) ", strCodeName, strCode, iPrice, iCount, iPrice * iCount); + if (strResult == "1") // 체결 { strLog += "체결"; } else if (strResult == "2") // 확인 @@ -62,14 +76,6 @@ namespace upper_limit_crawler else if (strResult == "4") // 접수 { strLog += "접수"; } - strLog += string.Format("[{0}:{1}] {2:###,###,###}원 {3:###,###,###}주 (총{4:###,###,###}원) ", strCodeName, strCode, iPrice, iCount, iPrice * iCount); - - if (strTradeType == "1") // 정상주문 - { strLog += " (정상주문)"; } - else if (strTradeType == "2") // 정정주문 - { strLog += " (정정주문)"; } - else if (strTradeType == "3") // 취소주문 - { strLog += " (취소주문)"; } UlUtil.Trace(strLog); } @@ -118,7 +124,9 @@ namespace upper_limit_crawler { //lock(lockBuy) { - int iCnt = iBidAmount / iUnitPrice; + while (UlUtil.GetLimitRemainCountRQ() <= 0) ; + + int iCnt = iBidAmount / iUnitPrice; CPTRADELib.CpTd0311 Td0311Bid = new CPTRADELib.CpTd0311(); Td0311Bid.SetInputValue(0, "2"); @@ -129,7 +137,7 @@ namespace upper_limit_crawler Td0311Bid.SetInputValue(7, "0"); Td0311Bid.SetInputValue(8, "03"); - Td0311Bid.BlockRequest(); + Td0311Bid.BlockRequest2(1); } } @@ -137,9 +145,12 @@ namespace upper_limit_crawler { //lock (lockSell) { - //long iCnt = (long)Math.Floor(fAskAmount/fCurPrice); - //iCnt=1; - CPTRADELib.CpTd0311 Td0311Ask = new CPTRADELib.CpTd0311(); + //long iCnt = (long)Math.Floor(fAskAmount/fCurPrice); + //iCnt=1; + + while (UlUtil.GetLimitRemainCountRQ() <= 0) ; + + CPTRADELib.CpTd0311 Td0311Ask = new CPTRADELib.CpTd0311(); Td0311Ask.SetInputValue(0, "1"); Td0311Ask.SetInputValue(1, m_astrAccounts[0]); @@ -149,7 +160,7 @@ namespace upper_limit_crawler Td0311Ask.SetInputValue(7, "0"); Td0311Ask.SetInputValue(8, "03"); - Td0311Ask.BlockRequest(); + Td0311Ask.BlockRequest2(1); } } @@ -157,8 +168,10 @@ namespace upper_limit_crawler { //lock (lockSell) { - //long iCnt = (long)Math.Floor(fAskAmount/fCurPrice); - //iCnt=1; + //long iCnt = (long)Math.Floor(fAskAmount/fCurPrice); + //iCnt=1; + + while (UlUtil.GetLimitRemainCountRQ() <= 0); CPTRADELib.CpTd0311 Td0311Ask = new CPTRADELib.CpTd0311(); @@ -170,7 +183,7 @@ namespace upper_limit_crawler Td0311Ask.SetInputValue(7, "0"); Td0311Ask.SetInputValue(8, "03"); - Td0311Ask.BlockRequest(); + Td0311Ask.BlockRequest2(1); } } } diff --git a/ULWatch.cs b/ULWatch.cs deleted file mode 100644 index ff42822..0000000 --- a/ULWatch.cs +++ /dev/null @@ -1,169 +0,0 @@ -using System; -using System.Collections; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace upper_limit_crawler -{ - class ULWatch : ULObj - { - const int WATCH_DELAY = 3000; - - DSCBO1Lib.StockMst2 m_StockMst2 = new DSCBO1Lib.StockMst2(); - int m_iWatchDelay = 0; - //bool m_bWatching = false; - - public ULWatch(ULDataMgr DataMgr) : base(DataMgr) - { - } - - void Check() - { - ////0 - (string) 종목 코드 - ////1 - (string) 종목명 - ////2 - (long) 시간(HHMM) - ////3 - (long) 현재가 - ////4 - (long) 전일대비 - ////5 - (char) 상태구분 - //// 코드 내용 - //// '1' 상한 - //// '2' 상승 - //// '3' 보합 - //// '4' 하한 - //// '5' 하락 - //// '6' 기세상한 - //// '7' 기세상승 - //// '8' 기세하한 - //// '9' 기세하락 - - ////6 - (long) 시가 - ////7 - (long) 고가 - ////8 - (long) 저가 - ////9 - (long) 매도호가 - ////10 - (long) 매수호가 - ////11 - (unsigned long) 거래량 [주의] 단위 1주 - ////12 - (long) 거래대금 [주의] 단위 천원 - ////13 - (long) 총매도잔량 - ////14 - (long) 총매수잔량 - ////15 - (long) 매도잔량 - ////16 - (long) 매수잔량 - ////17 - (unsigned long) 상장주식수 - ////18 - (long) 외국인보유비율(%) - ////19 - (long) 전일종가 - ////20 - (unsigned long) 전일거래량 - ////21 - (long) 체결강도 - ////22 - (unsigned long) 순간체결량 - ////23 - (char) 체결가비교 Flag - //// 코드 내용 - //// 'O' 매도 - //// 'B' 매수 - - ////24 - (char) 호가비교 Flag - //// 코드 내용 - //// 'O' 매도 - //// 'B' 매수 - - ////25- (char) 동시호가구분 - //// 코드 내용 - //// '1' 동시호가 - //// '2' 장중 - - ////26 - (long) 예상체결가 - ////27 - (long) 예상체결가 전일대비 - ////28 - (long) 예상체결가 상태구분 - //// 코드 내용 - //// '1' 상한 - //// '2' 상승 - //// '3' 보합 - //// '4' 하한 - //// '5' 하락 - //// '6' 기세상한 - //// '7' 기세상승 - //// '8' 기세하한 - //// '9' 기세하락 - - ////29- (unsigned long) 예상체결가 거래량 - - //if (m_bWatching == true || UlUtil.GetLimitRemainCountRQ() < 30) - // return; - - //List WatchList = m_DataMgr.GetWatchList(); - //if (WatchList.Count <= 0) - // return; - - //string strCodes = ""; - //for (int i = 0; i < WatchList.Count; i++) - //{ - // if (i > 0) - // strCodes += ","; - // strCodes += WatchList[i].m_strCode; - //} - //m_StockMst2.SetInputValue(0, strCodes); - - - //int iResult = 0; - //m_bWatching = true; - //iResult = m_StockMst2.BlockRequest2(1); - //bool bContinue = true; - - //while (bContinue == true) - //{ - // int iCnt = m_StockMst2.GetHeaderValue(0); - // for (int i = 0; i < iCnt; i++) - // { - // object Code = m_StockMst2.GetDataValue(0, i); - // object Name = m_StockMst2.GetDataValue(1, i); - // object Time = m_StockMst2.GetDataValue(2, i); - // object CurPrice = m_StockMst2.GetDataValue(3, i); - // object StartPrice = m_StockMst2.GetDataValue(6, i); - // object AskPrice = m_StockMst2.GetDataValue(9, i); - // object BidPrice = m_StockMst2.GetDataValue(10, i); - // object TradingVolume = m_StockMst2.GetDataValue(11, i); - // object AskCount = m_StockMst2.GetDataValue(15, i); - // object BidCount = m_StockMst2.GetDataValue(16, i); - // float fRatePerStart = ((int)CurPrice - (int)StartPrice) * 100 / (float)(int)StartPrice; - - // //if(fRatePerStart >= 9.5 && fRatePerStart <= 10.0 && - // // m_DataMgr.HasOwnList((string)Code) == false && m_DataMgr.HasDealingList((string)Code) == false) - // //{ - // // m_DataMgr.GetTrader().Buy((string)Code); - // // m_DataMgr.AddDealingList((string)Code); - // //} - // // insert to db - - // // extract if loss - - // // extract if trailing loss - // } - - - // bContinue = (m_StockMst2.Continue == 1); - // if (bContinue == true && UlUtil.GetLimitRemainCountRQ() >= 30) - // iResult = m_StockMst2.BlockRequest2(1); - //} - - //m_bWatching = false; - } - - public override void Refresh(int iCurTime) - { - if (m_iLastTime == 0) - { - base.Refresh(iCurTime); - return; - } - - int iDeltaT = iCurTime - m_iLastTime; - m_iWatchDelay -= iDeltaT; - if(m_iWatchDelay <= 0) - { - Check(); - m_iWatchDelay = WATCH_DELAY; - } - - base.Refresh(iCurTime); - } - } -} diff --git a/UlUtil.cs b/UlUtil.cs index e3f2110..761d430 100644 --- a/UlUtil.cs +++ b/UlUtil.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Diagnostics; using System.IO; using System.Linq; using System.Net; @@ -11,14 +12,22 @@ namespace upper_limit_crawler { public static class UlUtil { - static string m_strLogServer = "http://mjjo53.us.to:8000"; + //static string m_strLogServer = "http://mjjo53.us.to:8000"; static CPUTILLib.CpCybos m_Util = new CPUTILLib.CpCybos(); static TextBox m_tbLog = null; + static string m_strLogFileName; - public static void SetLogView(TextBox tbLog) + public static void Init(TextBox tbLog) { m_tbLog = tbLog; + + if (Debugger.IsAttached == true) + m_strLogFileName = Directory.GetParent(Environment.CurrentDirectory).Parent.FullName+"\\"; + m_strLogFileName += "log\\"; + if (Directory.Exists(m_strLogFileName) == false) + Directory.CreateDirectory(m_strLogFileName); + m_strLogFileName += "log-" + DateTime.Now.ToString("yyyy-MM-dd") + ".txt"; } public static string GetCurTimeString() @@ -66,8 +75,18 @@ namespace upper_limit_crawler public static void Trace(string strMsg) { string strLog = "["+GetCurTimeString()+"] "+strMsg; + + System.IO.File.AppendAllText(m_strLogFileName, strLog + Environment.NewLine); Console.WriteLine(strLog); - //m_tbLog.Text += strLog; + + bool bScrollToEnd = (m_tbLog.SelectionStart == m_tbLog.Text.Length); + m_tbLog.Text += strLog + Environment.NewLine; + if(bScrollToEnd == true) + { + m_tbLog.SelectionStart = m_tbLog.Text.Length; + m_tbLog.ScrollToCaret(); + } + //WebLog(m_strLogServer, strLog); } diff --git a/upper-limit-crawler.csproj b/upper-limit-crawler.csproj index 74d3803..d310f9e 100644 --- a/upper-limit-crawler.csproj +++ b/upper-limit-crawler.csproj @@ -71,7 +71,6 @@ - Form @@ -83,7 +82,6 @@ - ULBalanceDlg.cs