선물, 옵션 크롤링

db 조건 검색
결과 파일 추가
This commit is contained in:
2015-06-19 01:12:11 +09:00
parent 67e7e332fb
commit 9a8f11a285
6 changed files with 69480 additions and 39 deletions

35
Form1.Designer.cs generated
View File

@@ -30,7 +30,8 @@
{
this.btSearchCode = new System.Windows.Forms.Button();
this.lbFutCode = new System.Windows.Forms.Label();
this.btCrawling = new System.Windows.Forms.Button();
this.btCrawlingFuture = new System.Windows.Forms.Button();
this.btCrawlingOption = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// btSearchCode
@@ -52,22 +53,33 @@
this.lbFutCode.TabIndex = 1;
this.lbFutCode.Text = "unknown";
//
// btCrawling
// btCrawlingFuture
//
this.btCrawling.Location = new System.Drawing.Point(12, 54);
this.btCrawling.Name = "btCrawling";
this.btCrawling.Size = new System.Drawing.Size(106, 23);
this.btCrawling.TabIndex = 2;
this.btCrawling.Text = "Do Crawling";
this.btCrawling.UseVisualStyleBackColor = true;
this.btCrawling.Click += new System.EventHandler(this.btCrawling_Click);
this.btCrawlingFuture.Location = new System.Drawing.Point(12, 104);
this.btCrawlingFuture.Name = "btCrawlingFuture";
this.btCrawlingFuture.Size = new System.Drawing.Size(160, 100);
this.btCrawlingFuture.TabIndex = 2;
this.btCrawlingFuture.Text = "Future Crawling";
this.btCrawlingFuture.UseVisualStyleBackColor = true;
this.btCrawlingFuture.Click += new System.EventHandler(this.btCrawling_Click);
//
// btCrawlingOption
//
this.btCrawlingOption.Location = new System.Drawing.Point(231, 104);
this.btCrawlingOption.Name = "btCrawlingOption";
this.btCrawlingOption.Size = new System.Drawing.Size(143, 100);
this.btCrawlingOption.TabIndex = 3;
this.btCrawlingOption.Text = "Option Crawling";
this.btCrawlingOption.UseVisualStyleBackColor = true;
this.btCrawlingOption.Click += new System.EventHandler(this.btCrawlingOption_Click);
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(386, 405);
this.Controls.Add(this.btCrawling);
this.Controls.Add(this.btCrawlingOption);
this.Controls.Add(this.btCrawlingFuture);
this.Controls.Add(this.lbFutCode);
this.Controls.Add(this.btSearchCode);
this.Name = "Form1";
@@ -81,7 +93,8 @@
private System.Windows.Forms.Button btSearchCode;
private System.Windows.Forms.Label lbFutCode;
private System.Windows.Forms.Button btCrawling;
private System.Windows.Forms.Button btCrawlingFuture;
private System.Windows.Forms.Button btCrawlingOption;
}
}

175
Form1.cs
View File

@@ -7,19 +7,27 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using MySql.Data.MySqlClient;
namespace future_crawler
{
public partial class Form1 : Form
{
MySqlConnection m_DBCon;
CPUTILLib.CpFutureCode m_FutCode = new CPUTILLib.CpFutureCode();
string m_strTargetFutCode = "101K9";
string m_strTargetOptCode = "201K7255";
CPSYSDIBLib.FutOptChart m_FutChart = new CPSYSDIBLib.FutOptChart();
CPSYSDIBLib.FutOptChart m_FutOpChart = new CPSYSDIBLib.FutOptChart();
public Form1()
{
InitializeComponent();
string strConn = "Server=mjjo53.us.to;Database=futopt;Uid=mjjo;Pwd=whaudwls;";
m_DBCon = new MySqlConnection(strConn);
m_DBCon.Open();
}
private void btSearchCode_Click(object sender, EventArgs e)
@@ -39,41 +47,152 @@ namespace future_crawler
private void btCrawling_Click(object sender, EventArgs e)
{
long[] aFields = new long[1];
aFields[0] = 0;
//aFields[1] = 1;
//aFields[2] = 2;
//aFields[3] = 3;
//aFields[4] = 4;
// 필드값
//0: 날짜(ulong)
//1:시간(ulong) - hhmm(단, 차트구분을 초('S')로 설정한 경우에는 hhmmss)
//2:시가(ulong or float)
//3:고가(ulong or float)
//4:저가(ulong or float)
//5:종가(ulong or float)
//6:전일대비(long or float)
//8:거래량(ulong or ulonglong)
//9:거래대금(ulonglong)
//10:누적체결매도수량(ulong or ulonglong) - 주) 분,틱 요청일 때만 제공
//11:누적체결매수수량(ulong or ulonglong) - 주) 분,틱 요청일 때만 제공
//12: 사용하지 않음
//13: 사용하지 않음
//14: 사용하지 않음
//15: 사용하지 않음
//16: 사용하지 않음
//17: 사용하지 않음
//18:수정주가일자(ulong) - YYYYMMDD
//19:수정주가비율(float)
//20:기관순매수(long)
//21:기관누적순매수(long)
//22: 사용하지 않음
//23: 사용하지 않음
//24: 사용하지 않음
//25: 사용하지 않음
//26: 사용하지 않음
//27: 미결제약정
//28: 선물이론가(선물 일간데이터에서만 제공)
//29: 베이시스
//30: 옵션이론가 (옵션일 때만 제공)
//31: IV
//32: Delta
//33: Gamma
//34: Theta
//35: Vaga
//36: Rho
m_FutChart.SetInputValue(0, m_strTargetFutCode);
m_FutChart.SetInputValue(1, '1');
m_FutChart.SetInputValue(2, 20150617);
m_FutChart.SetInputValue(3, 20150601);
m_FutChart.SetInputValue(4, 0);
m_FutChart.SetInputValue(5, aFields);
m_FutChart.SetInputValue(6, 'S');
m_FutChart.SetInputValue(7, 1);
m_FutChart.SetInputValue(8, '0');
m_FutChart.SetInputValue(9, '0');
int iResult = m_FutChart.BlockRequest2(1);
m_FutOpChart.SetInputValue(0, m_strTargetFutCode);
m_FutOpChart.SetInputValue(1, '1');
m_FutOpChart.SetInputValue(2, 20150618);
m_FutOpChart.SetInputValue(3, 20150618);
m_FutOpChart.SetInputValue(4, 0);
m_FutOpChart.SetInputValue(5, new int[] { 0, 1, 5, 8, 9, 20 });
m_FutOpChart.SetInputValue(6, 'S');
m_FutOpChart.SetInputValue(7, 1);
m_FutOpChart.SetInputValue(8, '0');
m_FutOpChart.SetInputValue(9, '0');
int iResult = m_FutOpChart.BlockRequest2(1);
if (iResult != 0)
MessageBox.Show("결과가 이상함");
int iCnt = m_FutChart.GetHeaderValue(3);
int iFieldCnt = m_FutChart.GetHeaderValue(1);
for(int i=0; i<iCnt; i++)
{
ulong date = m_FutChart.GetDataValue(0, i);
ulong time = m_FutChart.GetDataValue(1, i);
ulong mp = m_FutChart.GetDataValue(2, i);
ulong hp = m_FutChart.GetDataValue(3, i);
ulong lp = m_FutChart.GetDataValue(4, i);
MySqlCommand cmd = new MySqlCommand();
Console.WriteLine(string.Format("{0}/{1}/{2}/{3}/{4}", date, time, mp, hp, lp));
bool bContinue = true;
while (bContinue == true)
{
MySqlTransaction trans = m_DBCon.BeginTransaction();
cmd.Connection = m_DBCon;
cmd.Transaction = trans;
int iCnt = m_FutOpChart.GetHeaderValue(3);
int iFieldCnt = m_FutOpChart.GetHeaderValue(1);
for (int i = 0; i < iCnt; i++)
{
ulong date = m_FutOpChart.GetDataValue(0, i);
ulong time = m_FutOpChart.GetDataValue(1, i);
float fp = m_FutOpChart.GetDataValue(2, i);
object deal_amount = m_FutOpChart.GetDataValue(3, i);
object deal_cash = m_FutOpChart.GetDataValue(4, i);
int comp_bid = m_FutOpChart.GetDataValue(5, i);
string strTime = string.Format("{0:d04}-{1:d02}-{2:d02} {3:d02}:{4:d02}:{5:d02}", date / 10000, (date % 10000) / 100, date % 100, time / 10000, (time % 10000) / 100, time % 100);
cmd.CommandText = string.Format("insert into future_list(code,date,fin_price,deal_amount,deal_cash,comp_bid) values('{0}','{1}',{2},{3},{4},{5})",
m_strTargetFutCode, strTime, fp, deal_amount, deal_cash, comp_bid);
cmd.ExecuteNonQuery();
Console.WriteLine(string.Format("{0}/{1}/{2}/{3}/{4}/{5}/{6}", m_strTargetFutCode, date, time, fp, deal_amount, deal_cash, comp_bid));
}
trans.Commit();
bContinue = (m_FutOpChart.Continue == 1);
iResult = m_FutOpChart.BlockRequest2(1);
}
Console.WriteLine("end.");
}
private void btCrawlingOption_Click(object sender, EventArgs e)
{
m_FutOpChart.SetInputValue(0, m_strTargetOptCode);
m_FutOpChart.SetInputValue(1, '1');
m_FutOpChart.SetInputValue(2, 20150618);
m_FutOpChart.SetInputValue(3, 20150618);
m_FutOpChart.SetInputValue(4, 0);
m_FutOpChart.SetInputValue(5, new int[] { 0, 1, 5, 8, 9, 20 });
m_FutOpChart.SetInputValue(6, 'S');
m_FutOpChart.SetInputValue(7, 1);
m_FutOpChart.SetInputValue(8, '0');
m_FutOpChart.SetInputValue(9, '0');
int iResult = m_FutOpChart.BlockRequest2(1);
if (iResult != 0)
MessageBox.Show("결과가 이상함");
MySqlCommand cmd = new MySqlCommand();
bool bContinue = true;
while (bContinue == true)
{
MySqlTransaction trans = m_DBCon.BeginTransaction();
cmd.Connection = m_DBCon;
cmd.Transaction = trans;
int iCnt = m_FutOpChart.GetHeaderValue(3);
int iFieldCnt = m_FutOpChart.GetHeaderValue(1);
for (int i = 0; i < iCnt; i++)
{
ulong date = m_FutOpChart.GetDataValue(0, i);
ulong time = m_FutOpChart.GetDataValue(1, i);
float fp = m_FutOpChart.GetDataValue(2, i);
object deal_amount = m_FutOpChart.GetDataValue(3, i);
object deal_cash = m_FutOpChart.GetDataValue(4, i);
int comp_bid = m_FutOpChart.GetDataValue(5, i);
string strTime = string.Format("{0:d04}-{1:d02}-{2:d02} {3:d02}:{4:d02}:{5:d02}", date / 10000, (date % 10000) / 100, date % 100, time / 10000, (time % 10000) / 100, time % 100);
cmd.CommandText = string.Format("insert into option_list(code,date,fin_price,deal_amount,deal_cash,comp_bid) values('{0}','{1}',{2},{3},{4},{5})",
m_strTargetOptCode, strTime, fp, deal_amount, deal_cash, comp_bid);
cmd.ExecuteNonQuery();
Console.WriteLine(string.Format("{0}/{1}/{2}/{3}/{4}/{5}/{6}", m_strTargetOptCode, date, time, fp, deal_amount, deal_cash, comp_bid));
}
trans.Commit();
bContinue = (m_FutOpChart.Continue == 1);
iResult = m_FutOpChart.BlockRequest2(1);
}
Console.WriteLine("end.");
}
}
}

View File

@@ -41,6 +41,7 @@
<ApplicationManifest>Properties\app.manifest</ApplicationManifest>
</PropertyGroup>
<ItemGroup>
<Reference Include="MySql.Data, Version=6.9.6.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d, processorArchitecture=MSIL" />
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />

69262
result/result.htm Normal file

File diff suppressed because it is too large Load Diff

11
sql/create.sql Normal file
View File

@@ -0,0 +1,11 @@
CREATE TABLE option_list
(
seq INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
CODE VARCHAR(10),
DATE DATETIME,
fin_price FLOAT,
deal_amount INT,
deal_cash BIGINT,
comp_bid INT
)

35
sql/search.sql Normal file
View File

@@ -0,0 +1,35 @@
SELECT * FROM option_list o WHERE future_list
SELECT o.date FROM option_list o IN (SELECT DATE FROM future_list f WHERE deal_cash >= 10000000000)
-- 특정 시간부터 30초 동안 현재가와 죄소값, 최대값
SELECT o.fin_price
FROM option_list o
WHERE o.date='2015-06-18 14:50:01'
SELECT o.fin_price, MAX(o.fin_price), MIN(o.fin_price)
FROM option_list o
WHERE o.date>='2015-06-18 14:50:01' AND o.date<=DATE_ADD('2015-06-18 14:50:01', INTERVAL 30 SECOND)
-- 100억이상의 거래량이 나온 시간의 옵션
SELECT sl.* FROM
(SELECT o.* FROM option_list o LEFT OUTER JOIN future_list f ON o.date=f.date AND f.deal_cash >= 10000000000) AS sl
-- 100억이상의 거래량이 나온 시간의 옵션과 향후 30초 동안의 옵션들
SELECT sl.deal_cash, sl.date, o2.date, o2.fin_price
FROM
(SELECT f.deal_cash, o.date FROM option_list o LEFT OUTER JOIN future_list f ON o.date=f.date AND f.deal_cash >= 10000000000) AS sl
LEFT OUTER JOIN option_list o2
ON o2.date>=sl.date AND o2.date<=DATE_ADD(sl.date, INTERVAL 30 SECOND)
-- 100억이상의 거래량이 나온 시간의 옵션과 향후 30초 동안의 옵션들 중 fin_price, min, max
SELECT sl.deal_cash, sl.date, o2.date, sl.fin_price, MIN(o2.fin_price), MAX(o2.fin_price)
FROM
(SELECT f.deal_cash, o.date, o.fin_price
FROM option_list o LEFT OUTER JOIN future_list f
ON o.date=f.date AND f.deal_cash >= 10000000000) AS sl
LEFT OUTER JOIN option_list o2
ON o2.date>=sl.date AND o2.date<=DATE_ADD(sl.date, INTERVAL 30 SECOND)
GROUP BY sl.date