From f6781a44b55a787ce7126949bc51a779157356c1 Mon Sep 17 00:00:00 2001 From: mjjo Date: Sun, 5 Feb 2017 13:55:18 +0900 Subject: [PATCH] =?UTF-8?q?-=20=EC=84=A4=EC=A0=95=20=EC=A0=80=EC=9E=A5=20-?= =?UTF-8?q?=20=EC=B2=B4=ED=81=AC=20=EC=9D=B4=ED=9B=84=20=EC=83=89=EC=83=81?= =?UTF-8?q?=20=EB=B3=80=ED=99=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Config.cs | 29 ++----- MarketWatch.Designer.cs | 110 ++++++++++++++++++++---- MarketWatch.cs | 186 +++++++++++++++++++++++----------------- MarketWatch.csproj | 1 + PriceCheck.cs | 88 +++++++++++++++++++ 5 files changed, 293 insertions(+), 121 deletions(-) create mode 100644 PriceCheck.cs diff --git a/Config.cs b/Config.cs index 597b758..32426af 100644 --- a/Config.cs +++ b/Config.cs @@ -18,9 +18,7 @@ namespace MarketWatchNS { m_Data.Add("account", ""); m_Data.Add("sub-account", ""); - m_Data.Add("bid-count", 5); - m_Data.Add("trailing-rate", 1.0f); - m_Data.Add("trailing-count", 2); + m_Data.Add("check-time", 5); Load(); } @@ -76,32 +74,15 @@ namespace MarketWatchNS return (string)m_Data["sub-account"]; } - public static void SetBidCount(int iCount) + public static void SetCheckTime(int iCheckTime) { - m_Data["bid-count"] = iCount; + m_Data["check-time"] = iCheckTime; Save(); } - public static int GetBidCount() + public static int GetCheckTime() { - return (int)m_Data["bid-count"]; - } - - public static void SetTrailing(float fTrailingRate, int iTrailingCnt) - { - m_Data["trailing-rate"] = fTrailingRate; - m_Data["trailing-count"] = iTrailingCnt; - Save(); - } - - public static float GetTrailingRate() - { - return (float)m_Data["trailing-rate"]; - } - - public static int GetTrailingCnt() - { - return (int)m_Data["trailing-count"]; + return (int)m_Data["check-time"]; } } } diff --git a/MarketWatch.Designer.cs b/MarketWatch.Designer.cs index 3967811..aa97e33 100644 --- a/MarketWatch.Designer.cs +++ b/MarketWatch.Designer.cs @@ -32,10 +32,15 @@ this.materialTabSelector1 = new MaterialSkin.Controls.MaterialTabSelector(); this.materialTabControl1 = new MaterialSkin.Controls.MaterialTabControl(); this.tabPage1 = new System.Windows.Forms.TabPage(); + this.lbInfo = new MaterialSkin.Controls.MaterialLabel(); this.splitContainer1 = new System.Windows.Forms.SplitContainer(); this.tbLog = new System.Windows.Forms.RichTextBox(); this.btCybos = new MaterialSkin.Controls.MaterialRaisedButton(); this.tabPage2 = new System.Windows.Forms.TabPage(); + this.materialLabel2 = new MaterialSkin.Controls.MaterialLabel(); + this.btApply = new MaterialSkin.Controls.MaterialFlatButton(); + this.tbCheckTime = new MaterialSkin.Controls.MaterialSingleLineTextField(); + this.materialLabel1 = new MaterialSkin.Controls.MaterialLabel(); this.materialLabel3 = new MaterialSkin.Controls.MaterialLabel(); this.lvItems = new MarketWatchNS.ListViewNF(); this.chSeq = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); @@ -49,7 +54,6 @@ this.chLowP = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); this.chHighPrice = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); this.chHighP = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); - this.lbInfo = new MaterialSkin.Controls.MaterialLabel(); this.materialTabControl1.SuspendLayout(); this.tabPage1.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).BeginInit(); @@ -100,6 +104,20 @@ this.tabPage1.Text = "Items"; this.tabPage1.UseVisualStyleBackColor = true; // + // lbInfo + // + this.lbInfo.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.lbInfo.AutoSize = true; + this.lbInfo.Depth = 0; + this.lbInfo.Font = new System.Drawing.Font("Microsoft Sans Serif", 11F); + this.lbInfo.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(222)))), ((int)(((byte)(0)))), ((int)(((byte)(0)))), ((int)(((byte)(0))))); + this.lbInfo.Location = new System.Drawing.Point(827, 6); + this.lbInfo.MouseState = MaterialSkin.MouseState.HOVER; + this.lbInfo.Name = "lbInfo"; + this.lbInfo.Size = new System.Drawing.Size(230, 18); + this.lbInfo.TabIndex = 4; + this.lbInfo.Text = "00 | 000 | yyyy-MM-dd HH:mm:ss"; + // // splitContainer1 // this.splitContainer1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) @@ -146,6 +164,10 @@ // tabPage2 // this.tabPage2.BackColor = System.Drawing.Color.White; + this.tabPage2.Controls.Add(this.materialLabel2); + this.tabPage2.Controls.Add(this.btApply); + this.tabPage2.Controls.Add(this.tbCheckTime); + this.tabPage2.Controls.Add(this.materialLabel1); this.tabPage2.Controls.Add(this.materialLabel3); this.tabPage2.Location = new System.Drawing.Point(4, 22); this.tabPage2.Name = "tabPage2"; @@ -154,6 +176,67 @@ this.tabPage2.TabIndex = 1; this.tabPage2.Text = "Preference"; // + // materialLabel2 + // + this.materialLabel2.AutoSize = true; + this.materialLabel2.Depth = 0; + this.materialLabel2.Font = new System.Drawing.Font("Microsoft Sans Serif", 11F); + this.materialLabel2.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(222)))), ((int)(((byte)(0)))), ((int)(((byte)(0)))), ((int)(((byte)(0))))); + this.materialLabel2.Location = new System.Drawing.Point(136, 37); + this.materialLabel2.MouseState = MaterialSkin.MouseState.HOVER; + this.materialLabel2.Name = "materialLabel2"; + this.materialLabel2.Size = new System.Drawing.Size(36, 18); + this.materialLabel2.TabIndex = 10; + this.materialLabel2.Text = "min."; + // + // btApply + // + this.btApply.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.btApply.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink; + this.btApply.Depth = 0; + this.btApply.Font = new System.Drawing.Font("Malgun Gothic", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(129))); + this.btApply.Location = new System.Drawing.Point(731, 479); + this.btApply.Margin = new System.Windows.Forms.Padding(4, 6, 4, 6); + this.btApply.MinimumSize = new System.Drawing.Size(120, 0); + this.btApply.MouseState = MaterialSkin.MouseState.HOVER; + this.btApply.Name = "btApply"; + this.btApply.Primary = false; + this.btApply.Size = new System.Drawing.Size(120, 36); + this.btApply.TabIndex = 9; + this.btApply.Text = "적용"; + this.btApply.UseVisualStyleBackColor = true; + this.btApply.Click += new System.EventHandler(this.btApply_Click); + // + // tbCheckTime + // + this.tbCheckTime.Depth = 0; + this.tbCheckTime.Hint = ""; + this.tbCheckTime.Location = new System.Drawing.Point(109, 37); + this.tbCheckTime.MouseState = MaterialSkin.MouseState.HOVER; + this.tbCheckTime.Name = "tbCheckTime"; + this.tbCheckTime.PasswordChar = '\0'; + this.tbCheckTime.RightToLeft = System.Windows.Forms.RightToLeft.Yes; + this.tbCheckTime.SelectedText = ""; + this.tbCheckTime.SelectionLength = 0; + this.tbCheckTime.SelectionStart = 0; + this.tbCheckTime.Size = new System.Drawing.Size(21, 23); + this.tbCheckTime.TabIndex = 8; + this.tbCheckTime.Text = "5"; + this.tbCheckTime.UseSystemPasswordChar = false; + // + // materialLabel1 + // + this.materialLabel1.AutoSize = true; + this.materialLabel1.Depth = 0; + this.materialLabel1.Font = new System.Drawing.Font("Microsoft Sans Serif", 11F); + this.materialLabel1.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(222)))), ((int)(((byte)(0)))), ((int)(((byte)(0)))), ((int)(((byte)(0))))); + this.materialLabel1.Location = new System.Drawing.Point(6, 37); + this.materialLabel1.MouseState = MaterialSkin.MouseState.HOVER; + this.materialLabel1.Name = "materialLabel1"; + this.materialLabel1.Size = new System.Drawing.Size(96, 18); + this.materialLabel1.TabIndex = 7; + this.materialLabel1.Text = "Check Time :"; + // // materialLabel3 // this.materialLabel3.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); @@ -166,7 +249,7 @@ this.materialLabel3.Name = "materialLabel3"; this.materialLabel3.Size = new System.Drawing.Size(162, 18); this.materialLabel3.TabIndex = 6; - this.materialLabel3.Text = "Version : 2017.02.01.09"; + this.materialLabel3.Text = "Version : 2017.02.03.11"; // // lvItems // @@ -201,17 +284,17 @@ // chCBTime // this.chCBTime.Text = "시간"; - this.chCBTime.Width = 37; + this.chCBTime.Width = 42; // // chRecvTime // this.chRecvTime.Text = "받은 시간"; - this.chRecvTime.Width = 66; + this.chRecvTime.Width = 80; // // chCode // this.chCode.Text = "코드"; - this.chCode.Width = 71; + this.chCode.Width = 73; // // chCodeName // @@ -249,19 +332,6 @@ this.chHighP.Text = "대비"; this.chHighP.TextAlign = System.Windows.Forms.HorizontalAlignment.Right; // - // lbInfo - // - this.lbInfo.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); - this.lbInfo.AutoSize = true; - this.lbInfo.Depth = 0; - this.lbInfo.Font = new System.Drawing.Font("Roboto", 11F); - this.lbInfo.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(222)))), ((int)(((byte)(0)))), ((int)(((byte)(0)))), ((int)(((byte)(0))))); - this.lbInfo.Location = new System.Drawing.Point(1007, 6); - this.lbInfo.MouseState = MaterialSkin.MouseState.HOVER; - this.lbInfo.Name = "lbInfo"; - this.lbInfo.Size = new System.Drawing.Size(0, 19); - this.lbInfo.TabIndex = 4; - // // MarketWatch // this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 12F); @@ -307,5 +377,9 @@ private System.Windows.Forms.ColumnHeader chCBTime; private System.Windows.Forms.ColumnHeader chRecvTime; private MaterialSkin.Controls.MaterialLabel lbInfo; + private MaterialSkin.Controls.MaterialLabel materialLabel2; + private MaterialSkin.Controls.MaterialFlatButton btApply; + private MaterialSkin.Controls.MaterialSingleLineTextField tbCheckTime; + private MaterialSkin.Controls.MaterialLabel materialLabel1; } } \ No newline at end of file diff --git a/MarketWatch.cs b/MarketWatch.cs index 05048c7..2438bb1 100644 --- a/MarketWatch.cs +++ b/MarketWatch.cs @@ -34,8 +34,8 @@ namespace MarketWatchNS public float m_fHighP = 0.0f; } - ConcurrentQueue m_ItemList = new ConcurrentQueue(); - System.Timers.Timer m_PriceCheckTimer = new System.Timers.Timer(); + List m_ItemList = new List(); + List m_PriceCheckList = new List(); System.Timers.Timer m_SystemTimer = new System.Timers.Timer(); public MarketWatch() @@ -47,6 +47,8 @@ namespace MarketWatchNS Util.SetLogView(tbLog); Config.Init(); + tbCheckTime.Text = Config.GetCheckTime().ToString(); + m_CybosHelper = new CybosHelper(this); var materialSkinManager = MaterialSkinManager.Instance; @@ -54,13 +56,8 @@ namespace MarketWatchNS materialSkinManager.Theme = MaterialSkinManager.Themes.DARK; materialSkinManager.ColorScheme = new ColorScheme(Primary.BlueGrey800, Primary.BlueGrey900, Primary.BlueGrey500, Accent.LightBlue200, TextShade.WHITE); - m_PriceCheckTimer.Interval = 500; - m_PriceCheckTimer.Elapsed += PriceCheckTimer_Elapsed; - m_PriceCheckTimer.Start(); - m_SystemTimer.Interval = 100; m_SystemTimer.Elapsed += SystemTimer_Elapsed; - ; m_SystemTimer.Start(); } @@ -69,75 +66,25 @@ namespace MarketWatchNS if(lbInfo.InvokeRequired) { lbInfo.Invoke(new Action(() => { - lbInfo.Text = string.Format("{0}|{1}", - m_CybosHelper.GetLimitRemainCountRQ(), - m_CybosHelper.GetLimitRemainCountSB()); + lbInfo.Text = string.Format("{0} | {1} | {2}", + m_CybosHelper.GetLimitRemainCountRQ(), + m_CybosHelper.GetLimitRemainCountSB(), + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); })); + + //lbInfo.Location = new Point(lbInfo.Parent.Width-lbInfo.Width, lbInfo.Top); } else { - lbInfo.Text = string.Format("{0}|{1}", - m_CybosHelper.GetLimitRemainCountRQ(), - m_CybosHelper.GetLimitRemainCountSB()); + lbInfo.Text = string.Format("{0} | {1}", + m_CybosHelper.GetLimitRemainCountRQ(), + m_CybosHelper.GetLimitRemainCountSB(), + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); + + //lbInfo.Location = new Point(lbInfo.Parent.Width-lbInfo.Width, lbInfo.Top); } - } - private void PriceCheckTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e) - { - foreach(ITEM Item in m_ItemList) - { - if(Item.m_iHighPrice > 0) - continue; - - if((DateTime.Now-Item.m_RecevedTime).Seconds < 20) - continue; - - m_CybosHelper.GetLowHighPrice(Item.m_strCode, Item.m_RecevedTime, 5, out Item.m_iLowPrice, out Item.m_iHighPrice); - Item.m_fLowP = (Item.m_iLowPrice-Item.m_iStartPrice)*100/(float)Item.m_iStartPrice; - Item.m_fHighP = (Item.m_iHighPrice-Item.m_iStartPrice)*100/(float)Item.m_iStartPrice; - - if(Item.m_iHighPrice > 0) - { - if(lvItems.InvokeRequired) - { - lvItems.Invoke(new Action(() => { - ListViewItem item = lvItems.Items.Cast().FirstOrDefault(s => s.SubItems[chSeq.Index].Text == Item.m_iSeq.ToString()); - - item.SubItems[chLowPrice.Index].Text = string.Format("{0:n0}", Item.m_iLowPrice); - item.SubItems[chLowP.Index].Text = string.Format("{0:n2}", Item.m_fLowP); - if(Item.m_fLowP > 0) - item.SubItems[chLowP.Index].ForeColor = Color.Red; - else if(Item.m_fLowP < 0) - item.SubItems[chLowP.Index].ForeColor = Color.Blue; - - item.SubItems[chHighPrice.Index].Text = string.Format("{0:n0}", Item.m_iHighPrice); - item.SubItems[chHighP.Index].Text = string.Format("{0:n2}", Item.m_fHighP); - if(Item.m_fHighP > 0) - item.SubItems[chHighP.Index].ForeColor = Color.Red; - else if(Item.m_fHighP < 0) - item.SubItems[chHighP.Index].ForeColor = Color.Blue; - })); - } - else - { - ListViewItem item = lvItems.Items.Cast().FirstOrDefault(s => s.SubItems[chSeq.Index].Text == Item.m_iSeq.ToString()); - - item.SubItems[chLowPrice.Index].Text = string.Format("{0:n0}", Item.m_iLowPrice); - item.SubItems[chLowP.Index].Text = string.Format("{0:n2}", Item.m_fLowP); - if(Item.m_fLowP > 0) - item.SubItems[chLowP.Index].ForeColor = Color.Red; - else if(Item.m_fLowP < 0) - item.SubItems[chLowP.Index].ForeColor = Color.Blue; - - item.SubItems[chHighPrice.Index].Text = string.Format("{0:n0}", Item.m_iHighPrice); - item.SubItems[chHighP.Index].Text = string.Format("{0:n2}", Item.m_fHighP); - if(Item.m_fHighP > 0) - item.SubItems[chHighP.Index].ForeColor = Color.Red; - else if(Item.m_fHighP < 0) - item.SubItems[chHighP.Index].ForeColor = Color.Blue; - } - } - } + m_PriceCheckList.RemoveAll(s => s.IsEnd()); } public void SetAccountList(string[] aAccountList) @@ -165,9 +112,8 @@ namespace MarketWatchNS Item.m_strCodeName = strCodeName; Item.m_iEventCode = iEventCode; Item.m_RecevedTime = DateTime.Now; - Item.m_iStartPrice = m_CybosHelper.GetCurPrice(strCode); - - m_ItemList.Enqueue(Item); + Item.m_iStartPrice = 0; + m_ItemList.Add(Item); if(lvItems.InvokeRequired) @@ -176,13 +122,13 @@ namespace MarketWatchNS lvItems.Items.Add(new ListViewItem(new string[] { iSeq.ToString(), - string.Format("{0}:{1}", iTime/100, iTime%100), - DateTime.Now.ToString("hh:MM:ss:fff"), + string.Format("{0:00}:{1:00}", iTime/100, iTime%100), + DateTime.Now.ToString("hh:mm:ss.fff"), strCode, strCodeName, m_CybosHelper.GetEventCodeStr(iEventCode), string.Format("{0:n0}", - Item.m_iStartPrice), + ""), "", "", "", @@ -196,13 +142,13 @@ namespace MarketWatchNS lvItems.Items.Add(new ListViewItem(new string[] { iSeq.ToString(), - string.Format("{0}:{1}", iTime/100, iTime%100), - DateTime.Now.ToString("hh:MM:ss:fff"), + string.Format("{0:00}:{1:00}", iTime/100, iTime%100), + DateTime.Now.ToString("hh:mm:ss.fff"), strCode, strCodeName, m_CybosHelper.GetEventCodeStr(iEventCode), string.Format("{0:n0}", - Item.m_iStartPrice), + ""), "", "", "", @@ -210,6 +156,80 @@ namespace MarketWatchNS })); lvItems.Items[lvItems.Items.Count-1].UseItemStyleForSubItems = false; } + + m_PriceCheckList.Add(new PriceCheck(iSeq, strCode, strCodeName, this, Config.GetCheckTime()*60)); + } + + public void OnReceivedStartPrice(int iSeq, int iStartPrice) + { + var Item = lvItems.Items.Cast().FirstOrDefault(s => s.SubItems[chSeq.Index].Text == iSeq.ToString()); + if(Item == default(ListViewItem)) + return; + + if(lvItems.InvokeRequired) + { + lvItems.Invoke(new Action(() => { + Item.SubItems[chStartPrice.Index].Text = string.Format("{0:n0}", iStartPrice); + })); + } + else + { + Item.SubItems[chStartPrice.Index].Text = string.Format("{0:n0}", iStartPrice); + } + } + + public void OnPriceCheckEnd(int iSeq, int iStartPrice, int iLowPrice, float fLowP, int iHighPrice, float fHighP) + { + if(lvItems.InvokeRequired) + { + lvItems.Invoke(new Action(() => { + var Item = lvItems.Items.Cast().FirstOrDefault(s => s.SubItems[chSeq.Index].Text == iSeq.ToString()); + if(Item == default(ListViewItem)) + return; + + Item.SubItems[chStartPrice.Index].BackColor = Color.FromArgb(255, 245, 245, 245); + Item.SubItems[chLowPrice.Index].BackColor = Color.FromArgb(255, 245, 245, 245); + Item.SubItems[chLowP.Index].BackColor = Color.FromArgb(255, 245, 245, 245); + Item.SubItems[chHighPrice.Index].BackColor = Color.FromArgb(255, 245, 245, 245); + Item.SubItems[chHighP.Index].BackColor = Color.FromArgb(255, 245, 245, 245); + + if(iHighPrice > 0) + { + Item.SubItems[chLowPrice.Index].Text = string.Format("{0:n0}", iLowPrice); + Item.SubItems[chLowPrice.Index].ForeColor = (iLowPrice > iStartPrice) ? Color.Red : (iLowPrice < iStartPrice) ? Color.Blue : Color.Black; + Item.SubItems[chLowP.Index].Text = string.Format("{0:n2}", fLowP-1.0f); + Item.SubItems[chLowP.Index].ForeColor = (fLowP > 1.0f) ? Color.Red : (fLowP < 1.0f) ? Color.Blue : Color.Black; + Item.SubItems[chHighPrice.Index].Text = string.Format("{0:n0}", iHighPrice); + Item.SubItems[chHighPrice.Index].ForeColor = (iHighPrice > iStartPrice) ? Color.Red : (iHighPrice < iStartPrice) ? Color.Blue : Color.Black; + Item.SubItems[chHighP.Index].Text = string.Format("{0:n2}", fHighP-1.0f); + Item.SubItems[chHighP.Index].ForeColor = (fHighP > 1.0f) ? Color.Red : (fHighP < 1.0f) ? Color.Blue : Color.Black; + } + })); + } + else + { + var Item = lvItems.Items.Cast().FirstOrDefault(s => s.SubItems[chSeq.Index].Text == iSeq.ToString()); + if(Item == default(ListViewItem)) + return; + + Item.SubItems[chStartPrice.Index].BackColor = Color.FromArgb(255, 245, 245, 245); + Item.SubItems[chLowPrice.Index].BackColor = Color.FromArgb(255, 245, 245, 245); + Item.SubItems[chLowP.Index].BackColor = Color.FromArgb(255, 245, 245, 245); + Item.SubItems[chHighPrice.Index].BackColor = Color.FromArgb(255, 245, 245, 245); + Item.SubItems[chHighP.Index].BackColor = Color.FromArgb(255, 245, 245, 245); + + if(iHighPrice > 0) + { + Item.SubItems[chLowPrice.Index].Text = string.Format("{0:n0}", iLowPrice); + Item.SubItems[chLowPrice.Index].ForeColor = (iLowPrice > iStartPrice) ? Color.Red : (iLowPrice < iStartPrice) ? Color.Blue : Color.Black; + Item.SubItems[chLowP.Index].Text = string.Format("{0:n2}", fLowP-1.0f); + Item.SubItems[chLowP.Index].ForeColor = (fLowP > 1.0f) ? Color.Red : (fLowP < 1.0f) ? Color.Blue : Color.Black; + Item.SubItems[chHighPrice.Index].Text = string.Format("{0:n0}", iHighPrice); + Item.SubItems[chHighPrice.Index].ForeColor = (iHighPrice > iStartPrice) ? Color.Red : (iHighPrice < iStartPrice) ? Color.Blue : Color.Black; + Item.SubItems[chHighP.Index].Text = string.Format("{0:n2}", fHighP-1.0f); + Item.SubItems[chHighP.Index].ForeColor = (fHighP > 1.0f) ? Color.Red : (fHighP < 1.0f) ? Color.Blue : Color.Black; + } + } } private void lvItems_ColumnClick(object sender, ColumnClickEventArgs e) @@ -220,6 +240,14 @@ namespace MarketWatchNS lvItems.Sorting = Order; lvItems.Sort(); } + + private void btApply_Click(object sender, EventArgs e) + { + int iCheckTime; + bool bParsed = int.TryParse(tbCheckTime.Text, out iCheckTime); + if(bParsed == true) + Config.SetCheckTime(iCheckTime); + } } class ListViewItemComparer : IComparer diff --git a/MarketWatch.csproj b/MarketWatch.csproj index eda1fd0..e6d6132 100644 --- a/MarketWatch.csproj +++ b/MarketWatch.csproj @@ -94,6 +94,7 @@ Component + diff --git a/PriceCheck.cs b/PriceCheck.cs new file mode 100644 index 0000000..d710ccf --- /dev/null +++ b/PriceCheck.cs @@ -0,0 +1,88 @@ +using DSCBO1Lib; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace MarketWatchNS +{ + public class PriceCheck + { + int m_iSeq; + string m_strCode; + string m_strCodeName; + int m_iStartPrice = int.MinValue; + int m_iLowPrice = int.MaxValue; + float m_fLowP = float.MaxValue; + int m_iHighPrice = int.MinValue; + float m_fHighP = float.MinValue; + int m_iCurPrice = int.MinValue; + + DateTime m_StartTime; + DateTime m_EndTime; + + StockCur m_StockCur = new StockCur(); + MarketWatch m_Listener = null; + bool m_bEnd = false; + + System.Timers.Timer m_Timer = new System.Timers.Timer(); + + public PriceCheck(int iSeq, string strCode, string strCodeName, MarketWatch Listener, int iTimeInSec) + { + m_iSeq = iSeq; + m_strCode = strCode; + m_strCodeName = strCodeName; + + m_Listener = Listener; + + m_StartTime = DateTime.Now; + m_EndTime = m_StartTime + TimeSpan.FromSeconds(iTimeInSec); + + m_StockCur.SetInputValue(0, strCode); + m_StockCur.Received += StockCur_Received; + m_StockCur.Subscribe(); + + m_Timer.Interval = iTimeInSec*1000; + m_Timer.Elapsed += Timer_Elapsed; + m_Timer.Start(); + } + + private void Timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e) + { + Stop(); + } + + public bool IsEnd() + { + return m_bEnd; + } + + private void Stop() + { + m_Listener.OnPriceCheckEnd(m_iSeq, m_iStartPrice, m_iLowPrice, m_fLowP, m_iHighPrice, m_fHighP); + m_StockCur.Unsubscribe(); + m_bEnd = true; + } + + private void StockCur_Received() + { + m_iCurPrice = m_StockCur.GetHeaderValue(13); + if(m_iStartPrice == int.MinValue) + { + m_iStartPrice = m_iCurPrice; + m_Listener.OnReceivedStartPrice(m_iSeq, m_iStartPrice); + } + + m_iLowPrice = Math.Min(m_iLowPrice, m_iCurPrice); + m_fLowP = m_iLowPrice/(float)m_iStartPrice; + m_iHighPrice = Math.Max(m_iHighPrice, m_iCurPrice); + m_fHighP = m_iHighPrice/(float)m_iStartPrice; + } + + public override string ToString() + { + return string.Format("[{0}] {1:n0}({2:n0} | {3:n0} | {4:n0})", m_strCodeName, m_iCurPrice, m_iStartPrice, m_iLowPrice, m_iHighPrice); + } + } +}