가격 체크 기능 추가
This commit is contained in:
160
NewsForm.cs
160
NewsForm.cs
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
@@ -17,6 +18,17 @@ namespace NewsCrawler
|
||||
{
|
||||
public partial class NewsForm : Form
|
||||
{
|
||||
class PRICE_CHECK_DATA
|
||||
{
|
||||
public int m_iID;
|
||||
public CodeList.CODE_VALUE m_Code;
|
||||
public int m_iPriceStart = 0;
|
||||
public int m_iPriceLow = 0;
|
||||
public int m_iPriceHigh = 0;
|
||||
public DateTime m_StartTime;
|
||||
}
|
||||
|
||||
|
||||
CybosHelper m_CybosHelper = null;
|
||||
CodeList m_CodeList = null;
|
||||
TextCondition m_Condition = null;
|
||||
@@ -27,7 +39,8 @@ namespace NewsCrawler
|
||||
bool m_bBrowserReload = false;
|
||||
bool m_bBuy = false;
|
||||
|
||||
|
||||
ConcurrentQueue<PRICE_CHECK_DATA> m_PriceCheckList = new ConcurrentQueue<PRICE_CHECK_DATA>();
|
||||
System.Timers.Timer m_PriceCheckTimer = new System.Timers.Timer();
|
||||
|
||||
public NewsForm()
|
||||
{
|
||||
@@ -37,6 +50,8 @@ namespace NewsCrawler
|
||||
Util.SetLogView(tbLog);
|
||||
m_CodeList = new CodeList();
|
||||
m_Condition = new TextCondition();
|
||||
m_CybosHelper = new CybosHelper(this);
|
||||
|
||||
MessageBox.Show("Keywords : \n\n" + m_Condition.GetKeywordsCnt());
|
||||
|
||||
|
||||
@@ -52,7 +67,7 @@ namespace NewsCrawler
|
||||
ReadFinacialNews(true);
|
||||
|
||||
|
||||
lvList.ListViewItemSorter = new ListViewItemComparer(0, SortOrder.Ascending);
|
||||
lvList.ListViewItemSorter = new ListViewItemComparer(chId.Index, SortOrder.Ascending);
|
||||
lvList.Sorting = SortOrder.Ascending;
|
||||
lvList.Sort();
|
||||
|
||||
@@ -66,15 +81,18 @@ namespace NewsCrawler
|
||||
lvList.Columns[chTime.Index].TextAlign = HorizontalAlignment.Right;
|
||||
lvList.Columns[chResponseT.Index].TextAlign = HorizontalAlignment.Right;
|
||||
lvList.Columns[chResT.Index].TextAlign = HorizontalAlignment.Right;
|
||||
lvList.Columns[chId.Index].TextAlign = HorizontalAlignment.Right;
|
||||
lvList.Columns[chPriceS.Index].TextAlign = HorizontalAlignment.Right;
|
||||
lvList.Columns[chPriceLow.Index].TextAlign = HorizontalAlignment.Right;
|
||||
lvList.Columns[chPriceHigh.Index].TextAlign = HorizontalAlignment.Right;
|
||||
|
||||
Console.WriteLine(string.Format("{0} ddd", m_CrawlTimer.SynchronizingObject));
|
||||
Console.WriteLine(string.Format("init thread {0}", System.Threading.Thread.CurrentThread.ManagedThreadId.ToString()));
|
||||
m_CrawlTimer.Elapsed+=CrawlTimer_Tick;
|
||||
m_CrawlTimer.Interval=m_iCrawlInterval;
|
||||
m_CrawlTimer.Start();
|
||||
|
||||
|
||||
m_CybosHelper = new CybosHelper(this);
|
||||
m_PriceCheckTimer.Interval = 5000;
|
||||
m_PriceCheckTimer.Elapsed += PriceCheckTimer_Elapsed;
|
||||
m_PriceCheckTimer.Start();
|
||||
|
||||
Test();
|
||||
}
|
||||
@@ -116,7 +134,16 @@ namespace NewsCrawler
|
||||
BuyItem(Code);
|
||||
}
|
||||
|
||||
void ProcessSearchAndBuy(string strTitle, string strName, string strCode, string strRef)
|
||||
void CheckPrice(int iID, CodeList.CODE_VALUE Code)
|
||||
{
|
||||
PRICE_CHECK_DATA CheckData = new PRICE_CHECK_DATA();
|
||||
CheckData.m_iID = iID;
|
||||
CheckData.m_Code = Code;
|
||||
CheckData.m_StartTime = DateTime.Now;
|
||||
m_PriceCheckList.Enqueue(CheckData);
|
||||
}
|
||||
|
||||
void ProcessSearchAndBuy(string strTitle, string strName, string strCode, string strRef, int iID)
|
||||
{
|
||||
CodeList.CODE_VALUE Code;
|
||||
if(strCode == "")
|
||||
@@ -169,6 +196,9 @@ namespace NewsCrawler
|
||||
Util.Log(Util.LOG_TYPE.DEBUG, string.Format("[NOT_MATCHED] [{0}] {1}({2})", strRef, strTitle, Code.ToString()));
|
||||
break;
|
||||
}
|
||||
|
||||
if(cbPriceCheck.Checked == true)
|
||||
CheckPrice(iID, Code);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -186,21 +216,38 @@ namespace NewsCrawler
|
||||
if(strURL != "" && lvList.Items.Cast<ListViewItem>().Any(s => s.SubItems[chLink.Index].Text == strURL))
|
||||
return;
|
||||
|
||||
lvList.Items.Add(new ListViewItem(new string[] { time.ToString("HH:mm:ss"), ResTime.ToString("HH:mm:ss:fff"), strRef, strTitle, string.Format("{0:0.0000} ms", responseT), strURL }));
|
||||
int iID = lvList.Items.Count+1;
|
||||
|
||||
lvList.Items.Add(new ListViewItem(new string[] {
|
||||
iID.ToString(),
|
||||
time.ToString("HH:mm:ss"),
|
||||
ResTime.ToString("HH:mm:ss:fff"),
|
||||
strRef,
|
||||
strTitle,
|
||||
string.Format("{0:0.0000} ms", responseT),
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
strURL }));
|
||||
|
||||
if(bInitial == false && chAutoSelect.Checked == true)
|
||||
{
|
||||
m_bBrowserReload = true;
|
||||
}
|
||||
|
||||
foreach(ColumnHeader col in lvList.Columns)
|
||||
col.Width = -2;
|
||||
|
||||
if(bInitial == false)
|
||||
{
|
||||
foreach(ColumnHeader col in lvList.Columns)
|
||||
{
|
||||
if(!(col == chPriceS || col == chPriceLow || col == chPriceHigh))
|
||||
col.Width = -2;
|
||||
}
|
||||
}
|
||||
|
||||
if(bInitial == false)
|
||||
{
|
||||
lvList.Sort();
|
||||
ProcessSearchAndBuy(strTitle, strName, strCode, strRef);
|
||||
ProcessSearchAndBuy(strTitle, strName, strCode, strRef, iID);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -744,6 +791,78 @@ namespace NewsCrawler
|
||||
m_CrawlTimer.Enabled = true;
|
||||
}
|
||||
|
||||
private void UpdateStartPrice(int iID, int iPrice)
|
||||
{
|
||||
if(lvList.InvokeRequired)
|
||||
{
|
||||
lvList.BeginInvoke((MethodInvoker)delegate ()
|
||||
{
|
||||
ListViewItem item = lvList.Items.Cast<ListViewItem>().FirstOrDefault(s => s.SubItems[chId.Index].Text == iID.ToString());
|
||||
item.SubItems[chPriceS.Index].Text = iPrice.ToString("n0");
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
ListViewItem item = lvList.Items.Cast<ListViewItem>().FirstOrDefault(s => s.SubItems[chId.Index].Text == iID.ToString());
|
||||
item.SubItems[chPriceS.Index].Text = iPrice.ToString("n0");
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateLowHighPrice(int iID, int iPriceStart, int iPriceLow, int iPriceHigh)
|
||||
{
|
||||
if(lvList.InvokeRequired)
|
||||
{
|
||||
lvList.BeginInvoke((MethodInvoker)delegate ()
|
||||
{
|
||||
ListViewItem item = lvList.Items.Cast<ListViewItem>().FirstOrDefault(s => s.SubItems[chId.Index].Text == iID.ToString());
|
||||
item.SubItems[chPriceLow.Index].Text = string.Format("{0:n0}({1:n}%)", iPriceLow, iPriceLow/(float)iPriceStart);
|
||||
item.SubItems[chPriceHigh.Index].Text = string.Format("{0:0}({1:n}%)", iPriceHigh, iPriceHigh/(float)iPriceStart);
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
ListViewItem item = lvList.Items.Cast<ListViewItem>().FirstOrDefault(s => s.SubItems[chId.Index].Text == iID.ToString());
|
||||
item.SubItems[chPriceLow.Index].Text = string.Format("{0:n0}({1:n}%)", iPriceLow, iPriceLow/(float)iPriceStart);
|
||||
item.SubItems[chPriceHigh.Index].Text = string.Format("{0:0}({1:n}%)", iPriceHigh, iPriceHigh/(float)iPriceStart);
|
||||
}
|
||||
}
|
||||
|
||||
private void PriceCheckTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
|
||||
{
|
||||
m_PriceCheckTimer.Enabled = false;
|
||||
|
||||
DateTime CurTime = DateTime.Now;
|
||||
foreach(PRICE_CHECK_DATA data in m_PriceCheckList)
|
||||
{
|
||||
if(data.m_iPriceStart == 0)
|
||||
{
|
||||
data.m_iPriceStart = m_CybosHelper.GetCurPrice(data.m_Code);
|
||||
UpdateStartPrice(data.m_iID, data.m_iPriceStart);
|
||||
}
|
||||
else if(data.m_iPriceHigh == 0 && (CurTime - data.m_StartTime).Minutes >= 1)
|
||||
{
|
||||
m_CybosHelper.GetLowHighPrice(data.m_Code, data.m_StartTime, 5, out data.m_iPriceLow, out data.m_iPriceHigh);
|
||||
if(data.m_iPriceHigh > 0)
|
||||
UpdateLowHighPrice(data.m_iID, data.m_iPriceStart, data.m_iPriceLow, data.m_iPriceHigh);
|
||||
}
|
||||
}
|
||||
|
||||
while(m_PriceCheckList.Count > 0)
|
||||
{
|
||||
PRICE_CHECK_DATA data;
|
||||
if(m_PriceCheckList.TryPeek(out data) == false)
|
||||
break;
|
||||
|
||||
if(data.m_iPriceHigh == 0)
|
||||
break;
|
||||
|
||||
m_PriceCheckList.TryDequeue(out data);
|
||||
}
|
||||
|
||||
|
||||
m_PriceCheckTimer.Enabled = true;
|
||||
}
|
||||
|
||||
private void lvList_SelectedIndexChanged(object sender, EventArgs e)
|
||||
{
|
||||
if(lvList.SelectedItems.Count <= 0)
|
||||
@@ -889,10 +1008,21 @@ namespace NewsCrawler
|
||||
{
|
||||
ListViewItem item1 = (ListViewItem)x;
|
||||
ListViewItem item2 = (ListViewItem)y;
|
||||
if(m_Order == SortOrder.Ascending)
|
||||
return string.Compare(item1.SubItems[m_iColumn].Text, item2.SubItems[m_iColumn].Text);
|
||||
|
||||
double num1;
|
||||
double num2;
|
||||
if(double.TryParse(item1.SubItems[m_iColumn].Text, out num1) &&
|
||||
double.TryParse(item2.SubItems[m_iColumn].Text, out num2))
|
||||
{
|
||||
return (num1>num2)?1:-1;
|
||||
}
|
||||
else
|
||||
return string.Compare(item2.SubItems[m_iColumn].Text, item1.SubItems[m_iColumn].Text);
|
||||
{
|
||||
if(m_Order == SortOrder.Ascending)
|
||||
return string.Compare(item1.SubItems[m_iColumn].Text, item2.SubItems[m_iColumn].Text);
|
||||
else
|
||||
return string.Compare(item2.SubItems[m_iColumn].Text, item1.SubItems[m_iColumn].Text);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user