162 lines
5.2 KiB
C#
162 lines
5.2 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Forms;
|
|
|
|
namespace upper_limit_crawler
|
|
{
|
|
class ULMonitor : ULObj
|
|
{
|
|
const int MONITOR_DELAY = 15000;
|
|
|
|
CPSYSDIBLib.CpSvrNew7043 m_7043 = new CPSYSDIBLib.CpSvrNew7043();
|
|
int m_iMonitorDelay = 0;
|
|
ListView lvWatch;
|
|
|
|
bool m_bRequesting = false;
|
|
|
|
public ULMonitor(ULDataMgr DataMgr) : base(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);
|
|
m_7043.SetInputValue(8, (short)m_DataMgr.m_Setting.m_fSearchMax);
|
|
}
|
|
|
|
public void SetView(ListView view)
|
|
{
|
|
lvWatch = view;
|
|
}
|
|
|
|
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);
|
|
m_7043.SetInputValue(8, (short)m_DataMgr.m_Setting.m_fSearchMax);
|
|
int iResult = m_7043.BlockRequest2(1);
|
|
|
|
//string strMsg = string.Format("종목/현재가/대비플래그/대비/대비율/거래량/시가/시가대비/시가대비율/연속일");
|
|
//UlUtil.Trace(strMsg);
|
|
// textBox1.Clear();
|
|
// textBox1.AppendText(strMsg + "\n");
|
|
|
|
m_DataMgr.ClearMonitor();
|
|
|
|
lvWatch.Items.Clear();
|
|
int iIdx = 1;
|
|
|
|
bool bContinue = true;
|
|
while (bContinue)
|
|
{
|
|
int iCnt = m_7043.GetHeaderValue(0);
|
|
for (int i = 0; i < iCnt; i++)
|
|
{
|
|
object Code = m_7043.GetDataValue(0, i);
|
|
object Name = m_7043.GetDataValue(1, i);
|
|
object CurPrice = m_7043.GetDataValue(2, i);
|
|
object flag = m_7043.GetDataValue(3, i);
|
|
object Comp = m_7043.GetDataValue(4, i);
|
|
object CompRate = m_7043.GetDataValue(5, i);
|
|
object Volume = m_7043.GetDataValue(6, i);
|
|
object StartPrice = m_7043.GetDataValue(7, i);
|
|
object StartPriceComp = m_7043.GetDataValue(8, i);
|
|
object StartPriceCompRate = m_7043.GetDataValue(9, i);
|
|
object SerialDay = m_7043.GetDataValue(10, i);
|
|
|
|
{
|
|
MONITOR_ITEM item;
|
|
item.Code = Code;
|
|
item.Name = Name;
|
|
item.CurPrice = CurPrice;
|
|
item.flag = flag;
|
|
item.Comp = Comp;
|
|
item.CompRate = CompRate;
|
|
item.Volume = Volume;
|
|
item.StartPrice = StartPrice;
|
|
item.StartPriceComp = StartPriceComp;
|
|
item.StartPriceCompRate = StartPriceCompRate;
|
|
item.SerialDay = SerialDay;
|
|
|
|
m_DataMgr.AddMonitor(item);
|
|
|
|
|
|
string[] row = { iIdx.ToString(), item.Name.ToString(), item.CurPrice.ToString(), item.Comp.ToString(), item.CompRate.ToString(), item.Volume.ToString(), 0.ToString(), 0.ToString() };
|
|
var listViewItem = new ListViewItem(row);
|
|
lvWatch.Items.Add(listViewItem);
|
|
iIdx++;
|
|
}
|
|
|
|
if ((float)StartPriceCompRate >= m_DataMgr.m_Setting.m_fBidMin &&
|
|
(float)StartPriceCompRate <= m_DataMgr.m_Setting.m_fBidMax &&
|
|
m_DataMgr.IsInBlackList((string)Code) == false)
|
|
{
|
|
// bid and add to black list
|
|
m_DataMgr.GetTrader().Buy((string)Code, (int)CurPrice, (int)m_DataMgr.m_Setting.m_fBidAmount);
|
|
m_DataMgr.AddBlackList((string)Code);
|
|
}
|
|
|
|
//if ((float)StartPriceCompRate >= 9.0f && (float)StartPriceCompRate <= 10.0f)
|
|
//{
|
|
// // add to watch list
|
|
// m_DataMgr.AddWatch((string)Code);
|
|
//}
|
|
|
|
//cmd.CommandText = string.Format("insert into trace(code, name, time, curprice, askcount, bidcount, startprice, tradingvolume, rateperstart) values('{0}', '{1}', '{2}', now, {3}, {4}, {5}, {6}, {7})",
|
|
// Code, Name, CurPrice, );
|
|
//cmd.ExecuteNonQuery();
|
|
|
|
//strMsg = string.Format("[{0}:{1}]/{2}/{3}/{4}/{5}/{6}/{7}/{8}/{9}/{10}",
|
|
// Name, Code,
|
|
// CurPrice, flag, Comp, CompRate,
|
|
// Volume, StartPrice, StartPriceComp, StartPriceCompRate,
|
|
// SerialDay);
|
|
//UlUtil.Trace(strMsg);
|
|
// textBox1.AppendText(strMsg + "\n");
|
|
}
|
|
|
|
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;
|
|
//col.AutoResize(ColumnHeaderAutoResizeStyle.HeaderSize);
|
|
}
|
|
|
|
m_bRequesting = false;
|
|
return true;
|
|
}
|
|
|
|
public override void Refresh(int iCurTime)
|
|
{
|
|
if(m_iLastTime == 0)
|
|
{
|
|
base.Refresh(iCurTime);
|
|
return;
|
|
}
|
|
|
|
int iDeltaT = iCurTime - m_iLastTime;
|
|
m_iMonitorDelay -= iDeltaT;
|
|
if(m_iMonitorDelay <= 0)
|
|
{
|
|
bool bRequest = Check();
|
|
m_iMonitorDelay = (bRequest == true) ? MONITOR_DELAY : 1000;
|
|
}
|
|
|
|
base.Refresh(iCurTime);
|
|
}
|
|
}
|
|
}
|