Files
upper-limit-crawler/MainForm.cs
mjjo f5af5eaef3 - ULWatchItem.Is5MAGoingUp() 함수 추가
- ULWatchItem.FillPrice() 함수 추가
2016-07-25 03:52:01 +09:00

293 lines
7.4 KiB
C#

using System;
using System.Windows.Forms;
using System.Collections;
using System.Reflection;
using System.Diagnostics;
namespace upper_limit_crawler
{
//struct ITEM
//{
// string m_strCode;
// DateTime m_Time;
// int m_iCurPrice;
// int m_iAskCount;
// int m_iBidCount;
// int m_iStartPrice;
// int m_iTradingVolume;
// float m_fRatePerStart;
//}
public partial class MainForm : Form
{
ArrayList m_TraceList = new ArrayList();
Timer m_MainTimer = new Timer();
int m_iLastTime = 0;
static ULDataMgr m_DataMgr = new ULDataMgr();
ULOwn m_Own = new ULOwn(m_DataMgr);
ULMonitorDlg m_MonitorDlg = null;
ULBalanceDlg m_BalanceDlg = null;
public MainForm()
{
InitializeComponent();
SetDoubleBuffered(tbLog);
UlUtil.Init(tbLog);
btApply_Click(null, null);
m_MonitorDlg = new ULMonitorDlg(m_DataMgr);
splitContainer3.Panel1.Controls.Add(m_MonitorDlg);
m_MonitorDlg.Dock = DockStyle.Fill;
m_MonitorDlg.Show();
m_BalanceDlg = new ULBalanceDlg(m_DataMgr);
splitContainer3.Panel2.Controls.Add(m_BalanceDlg);
m_BalanceDlg.Dock = DockStyle.Fill;
m_BalanceDlg.Show();
m_MainTimer.Interval = 10;
m_MainTimer.Tick += Refresh;
m_MainTimer.Start();
UlUtil.Trace("시작");
}
public static void SetDoubleBuffered(Control control)
{
// set instance non-public property with name "DoubleBuffered" to true
typeof(Control).InvokeMember("DoubleBuffered",
BindingFlags.SetProperty | BindingFlags.Instance | BindingFlags.NonPublic,
null, control, new object[] { true });
}
private bool IsOnTime()
{
DateTime CurTime = UlUtil.GetCurTime();
if (CurTime.DayOfWeek == DayOfWeek.Sunday || CurTime.DayOfWeek == DayOfWeek.Saturday)
return false;
if (CurTime.Hour < 8 || CurTime.Hour > 15)
return false;
if (CurTime.Hour == 8 && CurTime.Minute < 50)
return false;
if (CurTime.Hour == 15 && CurTime.Minute > 15)
return false;
return true;
}
private void Refresh(object sender, EventArgs e)
{
//if(IsOnTime() == false)
// return;
int iCurTime = Environment.TickCount;
if(m_iLastTime == 0)
{
m_iLastTime=iCurTime;
return;
}
if(cbStart.Checked == true && UlUtil.IsConnected() == false)
{
cbStart.Checked = false;
return;
}
int iDeltaT = iCurTime - m_iLastTime;
m_Own.Refresh(iCurTime);
lbRQCnt.Text = "RQ Count : " + UlUtil.GetLimitRemainCountRQ().ToString();
lbSBCnt.Text = "SB Count : " + UlUtil.GetLimitRemainCountSB().ToString();
statusBar1.Panels[1].Text = UlUtil.GetCurTimeString() + " ";
m_iLastTime = iCurTime;
}
void StartAll()
{
m_MonitorDlg.Start();
m_BalanceDlg.Start();
m_DataMgr.StartAll();
}
void StopAll()
{
m_MonitorDlg.Stop();
m_BalanceDlg.Stop();
m_DataMgr.StopAll();
}
private void cbStart_CheckedChanged(object sender, EventArgs e)
{
if (cbStart.Checked == true)
{
if (UlUtil.IsConnected() == false)
UlUtil.Reset();
if (UlUtil.IsConnected() == false)
{
cbStart.Checked = false;
MessageBox.Show("Cybos Plus를 실행해주세요");
return;
}
m_DataMgr.Init();
StartAll();
}
else
{
StopAll();
}
}
private void AddTrace(string strCode)
{
if (m_TraceList.Contains(strCode) == true)
return;
m_TraceList.Add(strCode);
}
private void btApply_Click(object sender, EventArgs e)
{
try
{
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;
m_DataMgr.m_Setting.m_fLossCut = float.Parse(tbLossCut.Text.Replace("%", ""))/100;
btCancel_Click(null, null);
}
catch(Exception ex)
{
UlUtil.Trace(ex.ToString());
}
}
private void btCancel_Click(object sender, EventArgs e)
{
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*100).ToString("0.0") + "%";
tbLossCut.Text = (m_DataMgr.m_Setting.m_fLossCut*100).ToString("0.0") + "%";
}
private void btCybos5_Click(object sender, EventArgs e)
{
string strappname = @"C:\DAISHIN\STARTER\ncStarter.exe";
Process.Start(strappname);
}
private void btCybosPlus_Click(object sender, EventArgs e)
{
string strappname = @"C:\DAISHIN\STARTER\ncStarter.exe";
Process.Start(strappname, @"/prj:cp");
}
private void btTimeSync_Click(object sender, EventArgs e)
{
UlUtil.SyncServerTime();
}
DSCBO1Lib.StockCur cur = new DSCBO1Lib.StockCur();
DSCBO1Lib.StockOutCur outCur = new DSCBO1Lib.StockOutCur();
string strCheckCode = "A004565";
private void button1_Click(object sender, EventArgs e)
{
{
DSCBO1Lib.StockMst mst = new DSCBO1Lib.StockMst();
mst.SetInputValue(0, strCheckCode);
mst.BlockRequest();
short time = mst.GetHeaderValue(4);
Console.WriteLine("StockMst : {0}", time);
}
{
DSCBO1Lib.StockMst2 mst2 = new DSCBO1Lib.StockMst2();
mst2.SetInputValue(0, strCheckCode);
mst2.BlockRequest();
long time = mst2.GetDataValue(2, 0);
Console.WriteLine("StockMst2 : {0}", time);
}
{
cur.SetInputValue(0, strCheckCode);
cur.Received += Cur_Received;
cur.SubscribeLatest();
}
{
outCur.SetInputValue(0, strCheckCode);
outCur.Received += OutCur_Received;
outCur.SubscribeLatest();
}
}
private void OutCur_Received()
{
long time = outCur.GetHeaderValue(1);
Console.WriteLine("StockOutCur : {0}", time);
}
private void Cur_Received()
{
long time = cur.GetHeaderValue(3);
long time2 = cur.GetHeaderValue(18);
Console.WriteLine("StockCur : {0} / {1}", time, time2);
}
private void btMATest_Click(object sender, EventArgs e)
{
CPSYSDIBLib.StockChart stockChart = new CPSYSDIBLib.StockChart();
stockChart.SetInputValue(0, "A043580");
stockChart.SetInputValue(1, '1');
stockChart.SetInputValue(2, "20160722");
stockChart.SetInputValue(3, "20160722");
stockChart.SetInputValue(5, new int[] { 0, 1, 2, 3, 4, 5, 6, 10 });
stockChart.SetInputValue(6, 'm');
stockChart.BlockRequest2(1);
int iCnt = (int)stockChart.GetHeaderValue(3);
int iFieldCnt = stockChart.GetHeaderValue(1);
string[] astrFieldName = stockChart.GetHeaderValue(2);
ULWatchItem item = new ULWatchItem();
for (int i=iCnt-1; i>=0; i--)
{
int iTime = (int)stockChart.GetDataValue(1, i);
int iPrice = (int)stockChart.GetDataValue(5, i);
int iVolume = (int)stockChart.GetDataValue(5, i);
iTime *= 100;
item.m_iCurPrice = iPrice;
item.InsertPriceNode(iTime, iPrice);
}
item.PrintChart();
}
}
}