diff --git a/Form1.Designer.cs b/Form1.Designer.cs
index 59711aa..c09472d 100644
--- a/Form1.Designer.cs
+++ b/Form1.Designer.cs
@@ -29,11 +29,13 @@
private void InitializeComponent()
{
this.btSearch = new System.Windows.Forms.Button();
+ this.textBox1 = new System.Windows.Forms.TextBox();
+ this.cbSearch = new System.Windows.Forms.CheckBox();
this.SuspendLayout();
//
// btSearch
//
- this.btSearch.Location = new System.Drawing.Point(40, 106);
+ this.btSearch.Location = new System.Drawing.Point(12, 12);
this.btSearch.Name = "btSearch";
this.btSearch.Size = new System.Drawing.Size(139, 88);
this.btSearch.TabIndex = 0;
@@ -41,21 +43,46 @@
this.btSearch.UseVisualStyleBackColor = true;
this.btSearch.Click += new System.EventHandler(this.btSearch_Click);
//
+ // textBox1
+ //
+ this.textBox1.Location = new System.Drawing.Point(12, 120);
+ this.textBox1.Multiline = true;
+ this.textBox1.Name = "textBox1";
+ this.textBox1.Size = new System.Drawing.Size(807, 510);
+ this.textBox1.TabIndex = 2;
+ //
+ // cbSearch
+ //
+ this.cbSearch.Appearance = System.Windows.Forms.Appearance.Button;
+ this.cbSearch.Location = new System.Drawing.Point(157, 12);
+ this.cbSearch.Name = "cbSearch";
+ this.cbSearch.Size = new System.Drawing.Size(151, 88);
+ this.cbSearch.TabIndex = 3;
+ this.cbSearch.Text = "Search";
+ this.cbSearch.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
+ this.cbSearch.UseVisualStyleBackColor = true;
+ this.cbSearch.CheckedChanged += new System.EventHandler(this.cbSearch_CheckedChanged);
+ //
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
- this.ClientSize = new System.Drawing.Size(454, 381);
+ this.ClientSize = new System.Drawing.Size(831, 642);
+ this.Controls.Add(this.cbSearch);
+ this.Controls.Add(this.textBox1);
this.Controls.Add(this.btSearch);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);
+ this.PerformLayout();
}
#endregion
private System.Windows.Forms.Button btSearch;
+ private System.Windows.Forms.TextBox textBox1;
+ private System.Windows.Forms.CheckBox cbSearch;
}
}
diff --git a/Form1.cs b/Form1.cs
index 34d980d..43bfe93 100644
--- a/Form1.cs
+++ b/Form1.cs
@@ -7,20 +7,56 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
-
+using MySql.Data.MySqlClient;
+using System.Collections;
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 Form1 : 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();
public Form1()
{
InitializeComponent();
+
+ string strConn = "Server=mjjo53.us.to;Database=upperlimit;Uid=mjjo;Pwd=whaudwls;charset=utf8;";
+ m_DBCon = new MySqlConnection(strConn);
+ m_DBCon.Open();
+
+ InitWatch();
+
+
+ timerWatch.Interval = 10 * 1000;
+ timerWatch.Tick += timerWatch_Tick;
+ //timerWatch.Start();
+
+ timerTrace.Interval = 10 * 1000;
+ timerTrace.Tick += timerTrace_Tick;
+ //timerTrace.Start();
}
- private void btSearch_Click(object sender, EventArgs e)
+ private void InitWatch()
{
m_7043.SetInputValue(0, '1');
m_7043.SetInputValue(1, '2');
@@ -31,18 +67,57 @@ namespace upper_limit_crawler
m_7043.SetInputValue(6, '0');
m_7043.SetInputValue(7, 0);
m_7043.SetInputValue(8, 30);
+ }
+
+ private void AddTrace(string strCode)
+ {
+ if (m_TraceList.Contains(strCode) == true)
+ return;
+
+ m_TraceList.Add(strCode);
+ }
+
+ private bool IsOnTime()
+ {
+ return true;
+
+ DateTime CurTime = DateTime.Now;
+ 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 timerWatch_Tick(object sender, EventArgs e)
+ {
+ if (IsOnTime() == false)
+ return;
int iResult = m_7043.BlockRequest2(1);
- if(iResult != 0)
+ if (iResult != 0)
{
MessageBox.Show("요청 에러");
return;
}
- Console.WriteLine(string.Format("종목/현재가/대비플래그/대비/대비율/거래량/시가/시가대비/시가대비율/연속일"));
+
+
+ //string strMsg = string.Format("종목/현재가/대비플래그/대비/대비율/거래량/시가/시가대비/시가대비율/연속일");
+ //Console.WriteLine(strMsg);
+ //textBox1.Clear();
+ //textBox1.AppendText(strMsg + "\n");
bool bContinue = true;
- while(bContinue)
+ while (bContinue)
{
int iCnt = m_7043.GetHeaderValue(0);
for (int i = 0; i < iCnt; i++)
@@ -59,17 +134,185 @@ namespace upper_limit_crawler
object StartPriceCompRate = m_7043.GetDataValue(9, i);
object SerialDay = m_7043.GetDataValue(10, i);
- Console.WriteLine(string.Format("[{0}:{1}]/{2}/{3}/{4}/{5}/{6}/{7}/{8}/{9}/{10}",
- Name, Code,
- CurPrice, flag, Comp, CompRate,
- DealAmount, StartPrice, StartPriceComp, StartPriceCompRate,
- SerialDay));
+ 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);
}
}
+
+ private void timerTrace_Tick(object sender, EventArgs e)
+ {
+ //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)
+ 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();
+ }
+
+
+ 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();
+ }
+ }
}
}
diff --git a/sql/create.sql b/sql/create.sql
new file mode 100644
index 0000000..44b34f8
--- /dev/null
+++ b/sql/create.sql
@@ -0,0 +1,19 @@
+DROP TABLE trace;
+CREATE TABLE trace
+(
+seq INT AUTO_INCREMENT,
+CODE VARCHAR(12),
+NAME VARCHAR(40),
+TIME DATETIME,
+startprice INT,
+curprice INT,
+rateperstart FLOAT,
+askprice INT,
+askcount INT,
+bidprice INT,
+bidcount INT,
+tradingvolume INT,
+
+
+PRIMARY KEY(seq)
+)
\ No newline at end of file
diff --git a/upper-limit-crawler.csproj b/upper-limit-crawler.csproj
index e7fb632..a2ff1c6 100644
--- a/upper-limit-crawler.csproj
+++ b/upper-limit-crawler.csproj
@@ -44,6 +44,7 @@
Properties\app.manifest
+
@@ -113,6 +114,15 @@
False
True
+
+ {859343F1-08FD-11D4-8231-00105A7C4F8C}
+ 1
+ 0
+ 0
+ tlbimp
+ False
+ True
+