검색, 구매, 구매 확인 구현
This commit is contained in:
330
MainForm.cs
330
MainForm.cs
@@ -9,6 +9,7 @@ using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using MySql.Data.MySqlClient;
|
||||
using System.Collections;
|
||||
using System.Reflection;
|
||||
|
||||
namespace upper_limit_crawler
|
||||
{
|
||||
@@ -26,19 +27,7 @@ namespace upper_limit_crawler
|
||||
|
||||
public partial class MainForm : Form
|
||||
{
|
||||
CPSYSDIBLib.CpSvrNew7043 m_7043 = new CPSYSDIBLib.CpSvrNew7043();
|
||||
DSCBO1Lib.StockMst2 m_StockMst2 = new DSCBO1Lib.StockMst2();
|
||||
|
||||
ArrayList m_TraceList = new ArrayList();
|
||||
|
||||
MySqlConnection m_DBCon;
|
||||
|
||||
Timer timerWatch = new Timer();
|
||||
Timer timerTrace = new Timer();
|
||||
|
||||
|
||||
|
||||
|
||||
ArrayList m_TraceList = new ArrayList();
|
||||
|
||||
Timer m_MainTimer = new Timer();
|
||||
int m_iLastTime = 0;
|
||||
@@ -47,64 +36,40 @@ namespace upper_limit_crawler
|
||||
ULMonitor m_Monitor = new ULMonitor(m_DataMgr);
|
||||
ULWatch m_Watch = new ULWatch(m_DataMgr);
|
||||
ULDealing m_Dealing = new ULDealing(m_DataMgr);
|
||||
ULOwn m_Own = new ULOwn(m_DataMgr);
|
||||
|
||||
public MainForm()
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
string strConn = "Server=mjjo53.us.to;Database=upperlimit;Uid=mjjo;Pwd=whaudwls;charset=utf8;";
|
||||
m_DBCon = new MySqlConnection(strConn);
|
||||
m_DBCon.Open();
|
||||
|
||||
InitWatch();
|
||||
m_DataMgr.m_Setting.m_fSearchMin = float.Parse(tbSearchMin.Text);
|
||||
m_DataMgr.m_Setting.m_fSearchMax = float.Parse(tbSearchMax.Text);
|
||||
m_DataMgr.m_Setting.m_fBidMin = float.Parse(tbBidMin.Text);
|
||||
m_DataMgr.m_Setting.m_fBidMax = float.Parse(tbBidMax.Text);
|
||||
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);
|
||||
m_DataMgr.m_Setting.m_fLossCut = float.Parse(tbLossCut.Text);
|
||||
|
||||
|
||||
SetDoubleBuffered(lvWatch);
|
||||
|
||||
m_MainTimer.Interval = 10;
|
||||
m_Monitor.SetView(lvWatch);
|
||||
|
||||
m_MainTimer.Interval = 10;
|
||||
m_MainTimer.Tick += Refresh;
|
||||
m_MainTimer.Start();
|
||||
|
||||
//timerWatch.Interval = 1 * 1000;
|
||||
//timerWatch.Tick += timerWatch_Tick;
|
||||
//timerWatch.Start();
|
||||
|
||||
//timerTrace.Interval = 1 * 1000;
|
||||
//timerTrace.Tick += timerTrace_Tick;
|
||||
//timerTrace.Start();
|
||||
}
|
||||
|
||||
private void InitWatch()
|
||||
{
|
||||
m_7043.SetInputValue(0, '1');
|
||||
m_7043.SetInputValue(1, '2');
|
||||
m_7043.SetInputValue(2, '1');
|
||||
m_7043.SetInputValue(3, 41);
|
||||
m_7043.SetInputValue(4, '1');
|
||||
m_7043.SetInputValue(5, '0');
|
||||
m_7043.SetInputValue(6, '0');
|
||||
m_7043.SetInputValue(7, 0);
|
||||
m_7043.SetInputValue(8, 30);
|
||||
}
|
||||
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 void Refresh(object sender, EventArgs e)
|
||||
{
|
||||
int iCurTime = Environment.TickCount;
|
||||
int iDeltaT = iCurTime - m_iLastTime;
|
||||
|
||||
m_Monitor.Refresh(iCurTime);
|
||||
|
||||
m_iLastTime = iCurTime;
|
||||
}
|
||||
|
||||
private void AddTrace(string strCode)
|
||||
{
|
||||
if (m_TraceList.Contains(strCode) == true)
|
||||
return;
|
||||
|
||||
m_TraceList.Add(strCode);
|
||||
}
|
||||
|
||||
private bool IsOnTime()
|
||||
private bool IsOnTime()
|
||||
{
|
||||
DateTime CurTime = DateTime.Now;
|
||||
if (CurTime.DayOfWeek == DayOfWeek.Sunday || CurTime.DayOfWeek == DayOfWeek.Saturday)
|
||||
@@ -122,222 +87,59 @@ namespace upper_limit_crawler
|
||||
return true;
|
||||
}
|
||||
|
||||
private void timerWatch_Tick(object sender, EventArgs e)
|
||||
private void Refresh(object sender, EventArgs e)
|
||||
{
|
||||
if (IsOnTime() == false)
|
||||
return;
|
||||
//if(IsOnTime() == false)
|
||||
// return;
|
||||
|
||||
int iResult = m_7043.BlockRequest2(1);
|
||||
if (iResult != 0)
|
||||
{
|
||||
MessageBox.Show("요청 에러");
|
||||
return;
|
||||
}
|
||||
int iCurTime = Environment.TickCount;
|
||||
int iDeltaT = iCurTime - m_iLastTime;
|
||||
|
||||
m_Monitor.Refresh(iCurTime);
|
||||
m_Watch.Refresh(iCurTime);
|
||||
m_Dealing.Refresh(iCurTime);
|
||||
m_Own.Refresh(iCurTime);
|
||||
|
||||
|
||||
string strMsg = string.Format("종목/현재가/대비플래그/대비/대비율/거래량/시가/시가대비/시가대비율/연속일");
|
||||
Console.WriteLine(strMsg);
|
||||
textBox1.Clear();
|
||||
textBox1.AppendText(strMsg + "\n");
|
||||
|
||||
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 DealAmount = 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);
|
||||
|
||||
if ((float)StartPriceCompRate >= 9.0f && (float)StartPriceCompRate <= 10.0f)
|
||||
AddTrace((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.GetType(), Code.GetType(),
|
||||
CurPrice.GetType(), flag.GetType(), Comp.GetType(), CompRate.GetType(),
|
||||
DealAmount.GetType(), StartPrice.GetType(), StartPriceComp.GetType(), StartPriceCompRate.GetType(),
|
||||
SerialDay.GetType());
|
||||
Console.WriteLine(strMsg);
|
||||
textBox1.AppendText(strMsg + "\n");
|
||||
}
|
||||
|
||||
bContinue = (m_7043.Continue == 1);
|
||||
if (bContinue == true)
|
||||
iResult = m_7043.BlockRequest2(1);
|
||||
}
|
||||
m_iLastTime = iCurTime;
|
||||
}
|
||||
|
||||
private void timerTrace_Tick(object sender, EventArgs e)
|
||||
private void AddTrace(string strCode)
|
||||
{
|
||||
//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 (IsOnTime() == false)
|
||||
if (m_TraceList.Contains(strCode) == true)
|
||||
return;
|
||||
|
||||
if (m_TraceList.Count <= 0)
|
||||
return;
|
||||
|
||||
string strCodes = "";
|
||||
for (int i = 0; i < m_TraceList.Count; i++)
|
||||
{
|
||||
if (i > 0)
|
||||
strCodes += ",";
|
||||
strCodes += m_TraceList[i];
|
||||
}
|
||||
m_StockMst2.SetInputValue(0, strCodes);
|
||||
|
||||
|
||||
int iResult = 0;
|
||||
iResult = m_StockMst2.BlockRequest2(1);
|
||||
bool bContinue = true;
|
||||
|
||||
MySqlTransaction trans = m_DBCon.BeginTransaction();
|
||||
MySqlCommand cmd = new MySqlCommand();
|
||||
cmd.Connection = m_DBCon;
|
||||
cmd.Transaction = trans;
|
||||
|
||||
DateTime CurTime = DateTime.Now;
|
||||
|
||||
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;
|
||||
|
||||
string time = CurTime.ToString("yyyy-MM-dd hh:mm:ss");
|
||||
time = time.Substring(0, 10) + " " + (int)Time / 100 + ":" + (int)Time % 100 + ":00";
|
||||
|
||||
// insert to db
|
||||
string query = string.Format("insert into trace(code, name, time, startprice, curprice, rateperstart, askprice, askcount, bidprice, bidcount, tradingvolume) values('{0}', '{1}', '{2}', {3}, {4}, {5}, {6}, {7}, {8}, {9}, {10})",
|
||||
Code, Name, time, StartPrice, CurPrice, fRatePerStart, AskPrice, AskCount, BidPrice, BidCount, TradingVolume);
|
||||
Console.WriteLine(query);
|
||||
|
||||
cmd.CommandText = query;
|
||||
cmd.ExecuteNonQuery();
|
||||
|
||||
|
||||
// extract if loss
|
||||
|
||||
// extract if trailing loss
|
||||
}
|
||||
|
||||
|
||||
bContinue = (m_StockMst2.Continue == 1);
|
||||
if (bContinue == true)
|
||||
iResult = m_StockMst2.BlockRequest2(1);
|
||||
}
|
||||
|
||||
trans.Commit();
|
||||
m_TraceList.Add(strCode);
|
||||
}
|
||||
|
||||
private void btApply_Click(object sender, EventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
m_DataMgr.m_Setting.m_fSearchMin = float.Parse(tbSearchMin.Text);
|
||||
m_DataMgr.m_Setting.m_fSearchMax = float.Parse(tbSearchMax.Text);
|
||||
m_DataMgr.m_Setting.m_fBidMin = float.Parse(tbBidMin.Text);
|
||||
m_DataMgr.m_Setting.m_fBidMax = float.Parse(tbBidMax.Text);
|
||||
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);
|
||||
m_DataMgr.m_Setting.m_fLossCut = float.Parse(tbLossCut.Text);
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
UlUtil.Trace(ex.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
private void btSearch_Click(object sender, EventArgs e)
|
||||
{
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
private void cbSearch_CheckedChanged(object sender, EventArgs e)
|
||||
{
|
||||
if (cbSearch.Checked == true)
|
||||
{
|
||||
timerWatch.Start();
|
||||
timerTrace.Start();
|
||||
}
|
||||
else
|
||||
{
|
||||
timerWatch.Stop();
|
||||
timerTrace.Stop();
|
||||
}
|
||||
}
|
||||
}
|
||||
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");
|
||||
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");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user