- 제3자배정 추가

- 영업실적 추가
This commit is contained in:
2017-01-27 01:22:11 +09:00
parent 16733892b7
commit b58125455f
7 changed files with 352 additions and 34 deletions

View File

@@ -20,7 +20,8 @@ namespace NewsCrawler
{
m_Data.Add("manual-price", "100000");
m_Data.Add("buy-price", "1000000");
m_Data.Add("supply-contract-rate", "5.0");
m_Data.Add("supply-contract-rate", "50.0");
m_Data.Add("revenue-rate", "50.0");
Load();
int iIdx = 1;
@@ -126,6 +127,19 @@ namespace NewsCrawler
return fRate;
}
public static void SetRevenueRate(float fRate)
{
m_Data["revenue-rate"] = fRate.ToString();
Save();
}
public static float GetRevenueRate()
{
float fRate;
float.TryParse(m_Data["revenue-rate"], out fRate);
return fRate;
}
public static string GetDartAPIKey()
{
if(m_iDartAPIKeyCnt <= 0)

86
ConfigForm.Designer.cs generated
View File

@@ -63,9 +63,12 @@
this.groupBox11 = new System.Windows.Forms.GroupBox();
this.btnAccountApply = new System.Windows.Forms.Button();
this.groupBox12 = new System.Windows.Forms.GroupBox();
this.label5 = new System.Windows.Forms.Label();
this.tbSupplyContractRate = new System.Windows.Forms.TextBox();
this.label6 = new System.Windows.Forms.Label();
this.tbSupplyContractRate = new System.Windows.Forms.TextBox();
this.label5 = new System.Windows.Forms.Label();
this.label7 = new System.Windows.Forms.Label();
this.tbRevenueRate = new System.Windows.Forms.TextBox();
this.label8 = new System.Windows.Forms.Label();
this.groupBox1.SuspendLayout();
this.groupBox2.SuspendLayout();
this.groupBox6.SuspendLayout();
@@ -433,36 +436,19 @@
//
// groupBox12
//
this.groupBox12.Controls.Add(this.label7);
this.groupBox12.Controls.Add(this.tbRevenueRate);
this.groupBox12.Controls.Add(this.label8);
this.groupBox12.Controls.Add(this.label6);
this.groupBox12.Controls.Add(this.tbSupplyContractRate);
this.groupBox12.Controls.Add(this.label5);
this.groupBox12.Location = new System.Drawing.Point(280, 316);
this.groupBox12.Name = "groupBox12";
this.groupBox12.Size = new System.Drawing.Size(262, 57);
this.groupBox12.Size = new System.Drawing.Size(262, 82);
this.groupBox12.TabIndex = 19;
this.groupBox12.TabStop = false;
this.groupBox12.Text = "공시";
//
// label5
//
this.label5.AutoSize = true;
this.label5.Location = new System.Drawing.Point(28, 23);
this.label5.Name = "label5";
this.label5.Size = new System.Drawing.Size(77, 12);
this.label5.TabIndex = 0;
this.label5.Text = "공급계약체결";
//
// tbSupplyContractRate
//
this.tbSupplyContractRate.Location = new System.Drawing.Point(111, 20);
this.tbSupplyContractRate.Name = "tbSupplyContractRate";
this.tbSupplyContractRate.Size = new System.Drawing.Size(100, 21);
this.tbSupplyContractRate.TabIndex = 1;
this.tbSupplyContractRate.Text = "5.0";
this.tbSupplyContractRate.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
this.tbSupplyContractRate.TextChanged += new System.EventHandler(this.tbSupplyContractRate_TextChanged);
this.tbSupplyContractRate.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.tbSupplyContractRate_KeyPress);
//
// label6
//
this.label6.AutoSize = true;
@@ -472,11 +458,60 @@
this.label6.TabIndex = 2;
this.label6.Text = "%";
//
// tbSupplyContractRate
//
this.tbSupplyContractRate.Location = new System.Drawing.Point(136, 20);
this.tbSupplyContractRate.Name = "tbSupplyContractRate";
this.tbSupplyContractRate.Size = new System.Drawing.Size(73, 21);
this.tbSupplyContractRate.TabIndex = 1;
this.tbSupplyContractRate.Text = "5.0";
this.tbSupplyContractRate.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
this.tbSupplyContractRate.TextChanged += new System.EventHandler(this.tbSupplyContractRate_TextChanged);
this.tbSupplyContractRate.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.tbSupplyContractRate_KeyPress);
//
// label5
//
this.label5.AutoSize = true;
this.label5.Location = new System.Drawing.Point(28, 23);
this.label5.Name = "label5";
this.label5.Size = new System.Drawing.Size(77, 12);
this.label5.TabIndex = 0;
this.label5.Text = "공급계약체결";
//
// label7
//
this.label7.AutoSize = true;
this.label7.Location = new System.Drawing.Point(217, 50);
this.label7.Name = "label7";
this.label7.Size = new System.Drawing.Size(15, 12);
this.label7.TabIndex = 5;
this.label7.Text = "%";
//
// tbRevenueRate
//
this.tbRevenueRate.Location = new System.Drawing.Point(136, 47);
this.tbRevenueRate.Name = "tbRevenueRate";
this.tbRevenueRate.Size = new System.Drawing.Size(73, 21);
this.tbRevenueRate.TabIndex = 4;
this.tbRevenueRate.Text = "5.0";
this.tbRevenueRate.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
this.tbRevenueRate.TextChanged += new System.EventHandler(this.tbRevenueRate_TextChanged);
this.tbRevenueRate.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.tbRevenueRate_KeyPress);
//
// label8
//
this.label8.AutoSize = true;
this.label8.Location = new System.Drawing.Point(28, 50);
this.label8.Name = "label8";
this.label8.Size = new System.Drawing.Size(87, 12);
this.label8.TabIndex = 3;
this.label8.Text = "영업(잠정)실적";
//
// ConfigForm
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(548, 385);
this.ClientSize = new System.Drawing.Size(548, 441);
this.Controls.Add(this.groupBox12);
this.Controls.Add(this.groupBox11);
this.Controls.Add(this.groupBox10);
@@ -548,5 +583,8 @@
private System.Windows.Forms.Label label6;
private System.Windows.Forms.TextBox tbSupplyContractRate;
private System.Windows.Forms.Label label5;
private System.Windows.Forms.Label label7;
private System.Windows.Forms.TextBox tbRevenueRate;
private System.Windows.Forms.Label label8;
}
}

View File

@@ -156,5 +156,18 @@ namespace NewsCrawler
if(char.IsDigit(e.KeyChar) == false && e.KeyChar != '.')
e.Handled = true;
}
private void tbRevenueRate_TextChanged(object sender, EventArgs e)
{
float fRevenueRate;
float.TryParse(tbRevenueRate.Text, out fRevenueRate);
m_Listener.OnRevenueRateChanged(fRevenueRate);
}
private void tbRevenueRate_KeyPress(object sender, KeyPressEventArgs e)
{
if (char.IsDigit(e.KeyChar) == false && e.KeyChar != '.')
e.Handled = true;
}
}
}

View File

@@ -41,6 +41,9 @@ namespace NewsCrawler
return;
ReadSupplyContract(false, "강스템바이오텍", "http://m.dart.fss.or.kr/viewer/main.st?rcpNo=20170111900149");
ReadRevenue(false, "제일기획", "http://m.dart.fss.or.kr/viewer/main.st?rcpNo=20170126800508");
ReadRevenue(false, "LS산전", "http://m.dart.fss.or.kr/viewer/main.st?rcpNo=20170126800581");
ReadRightsIssue(false, "옴니텔", "http://m.dart.fss.or.kr/viewer/main.st?rcpNo=20170126000525");
}
void ResponseAsiaE(IAsyncResult result)
@@ -396,7 +399,7 @@ namespace NewsCrawler
float fRate;
float.TryParse(strRate, out fRate);
m_Listener.OnReceivedSupplyContract(State.m_strCodeName, fRate);
break;
return;
}
}
}
@@ -437,6 +440,161 @@ namespace NewsCrawler
}
}
void ResponseRevenue(IAsyncResult result)
{
REQUEST_STATUS State = (REQUEST_STATUS)result.AsyncState;
HttpWebRequest HttpReq = State.m_HTTPReq;
bool bInitial = State.m_bInitial;
State.m_Timer.Stop();
try
{
using (HttpWebResponse response = (HttpWebResponse)HttpReq.GetResponse())
{
using (Stream dataStream = response.GetResponseStream())
{
using (StreamReader reader = new StreamReader(dataStream, Encoding.GetEncoding("utf-8")))
{
string responseFromServer = WebUtility.HtmlDecode(reader.ReadToEnd());
dynamic jObj = Newtonsoft.Json.JsonConvert.DeserializeObject(responseFromServer);
string strBody = jObj["reportBody"];
strBody = strBody.Replace("\\\"", "\"");
strBody = strBody.Replace("\r\n", "");
HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
doc.LoadHtml(strBody);
string strXPath = "//tr";
var lists = doc.DocumentNode.SelectNodes(strXPath);
foreach (var item in lists)
{
var cols = item.SelectNodes(".//td");
foreach (var col in cols)
{
if (col.InnerText.Contains("당기순이익") == true)
{
string strRate = cols[cols.Count - 1].InnerText;
strRate = strRate.Replace("%", "");
strRate = strRate.Replace(" ", "");
float fRate;
float.TryParse(strRate, NumberStyles.Float, CultureInfo.InvariantCulture, out fRate);
m_Listener.OnReceivedRevenue(State.m_strCodeName, fRate);
return;
}
}
}
}
}
}
HttpReq.EndGetResponse(result);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message + Environment.NewLine + ex.StackTrace);
}
}
private void ReadRevenue(bool bInitial, string strCodeName, string strURL)
{
if (m_iDartAPIRetry <= 0)
return;
try
{
HttpWebRequest HttpReq = WebRequest.Create(strURL) as HttpWebRequest;
HttpReq.Credentials = CredentialCache.DefaultCredentials;
HttpReq.Timeout = 2000;
REQUEST_STATUS State = new REQUEST_STATUS();
State.m_HTTPReq = HttpReq;
State.m_bInitial = bInitial;
State.m_Timer.Start();
State.m_strCodeName = strCodeName;
HttpReq.BeginGetResponse(new AsyncCallback(ResponseRevenue), State);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message + Environment.NewLine + ex.StackTrace);
}
}
void ResponseRightsIssue(IAsyncResult result)
{
REQUEST_STATUS State = (REQUEST_STATUS)result.AsyncState;
HttpWebRequest HttpReq = State.m_HTTPReq;
bool bInitial = State.m_bInitial;
State.m_Timer.Stop();
try
{
using (HttpWebResponse response = (HttpWebResponse)HttpReq.GetResponse())
{
using (Stream dataStream = response.GetResponseStream())
{
using (StreamReader reader = new StreamReader(dataStream, Encoding.GetEncoding("utf-8")))
{
string responseFromServer = WebUtility.HtmlDecode(reader.ReadToEnd());
dynamic jObj = Newtonsoft.Json.JsonConvert.DeserializeObject(responseFromServer);
string strBody = jObj["reportBody"];
strBody = strBody.Replace("\\\"", "\"");
strBody = strBody.Replace("\r\n", "");
HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
doc.LoadHtml(strBody);
string strXPath = "//tr";
var lists = doc.DocumentNode.SelectNodes(strXPath);
foreach (var item in lists)
{
var cols = item.SelectNodes(".//td");
for(int i=0; i<cols.Count-1; i++)
{
if(cols[i].InnerText.Contains("증자방식") && cols[i+1].InnerText.Contains("제3자배정증자"))
{
m_Listener.OnReceivedRightsIssue(State.m_strCodeName);
return;
}
}
}
}
}
}
HttpReq.EndGetResponse(result);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message + Environment.NewLine + ex.StackTrace);
}
}
private void ReadRightsIssue(bool bInitial, string strCodeName, string strURL)
{
if (m_iDartAPIRetry <= 0)
return;
try
{
HttpWebRequest HttpReq = WebRequest.Create(strURL) as HttpWebRequest;
HttpReq.Credentials = CredentialCache.DefaultCredentials;
HttpReq.Timeout = 2000;
REQUEST_STATUS State = new REQUEST_STATUS();
State.m_HTTPReq = HttpReq;
State.m_bInitial = bInitial;
State.m_Timer.Start();
State.m_strCodeName = strCodeName;
HttpReq.BeginGetResponse(new AsyncCallback(ResponseRightsIssue), State);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message + Environment.NewLine + ex.StackTrace);
}
}
void ResponseDartAPI(IAsyncResult result)
{
REQUEST_STATUS State = (REQUEST_STATUS)result.AsyncState;
@@ -475,12 +633,14 @@ namespace NewsCrawler
string strTitle = data["rpt_nm"];
string strCodeName = data["crp_nm"];
string strURL = "http://m.dart.fss.or.kr/html_mdart/MD1007.html?rcpNo=" + data["rcp_no"];
string strViewURL = "http://m.dart.fss.or.kr/viewer/main.st?rcpNo=" + data["rcp_no"];
if (strCodeName != "" && strTitle.Contains("공급계약체결") && m_Listener.IsDuplicatedURL(strURL) == false)
{
string strURL2 = "http://m.dart.fss.or.kr/viewer/main.st?rcpNo=" + data["rcp_no"];
ReadSupplyContract(bInitial, strCodeName, strURL2);
}
ReadSupplyContract(bInitial, strCodeName, strViewURL);
else if(strCodeName != "" && strTitle.Contains("영업(잠정)실적(공정공시)") && m_Listener.IsDuplicatedURL(strURL) == false)
ReadRevenue(bInitial, strCodeName, strViewURL);
else if(strCodeName != "" && strTitle.Contains("유상증자결정") && m_Listener.IsDuplicatedURL(strURL) == false)
ReadRightsIssue(bInitial, strCodeName, strViewURL);
m_Listener.InsertItem(strTitle, strCodeName, "",
DateTime.ParseExact(strTime, "HH:mm", CultureInfo.CurrentCulture),

Binary file not shown.

View File

@@ -89,6 +89,7 @@ namespace NewsCrawler
//ExcelHandler m_Excel = null;
float m_fSupplyContractRate;
float m_fRevenueRate;
object m_lvListLock = new object();
@@ -109,6 +110,7 @@ namespace NewsCrawler
m_CybosHelper = new CybosHelper(this);
m_Crawler = new Crawler(this);
m_fSupplyContractRate = Config.GetSupplyContractRate();
m_fRevenueRate = Config.GetRevenueRate();
Util.Log(Util.LOG_TYPE.VERVOSE, "========== NewsCrawler 실행 ==========");
@@ -340,12 +342,102 @@ namespace NewsCrawler
m_CodeList.AddDuplicatedList(Code.m_strCode, Code.m_strName);
}
public void OnReceivedRevenue(string strCodeName, float fRate)
{
CodeList.CODE_VALUE Code = m_CodeList.GetCodeByName(strCodeName);
if (Code == null)
{
Util.Log(Util.LOG_TYPE.VERVOSE, string.Format("[DartAPI][영업실적] 종목을 찾을 수 없음({0}, {1}%", strCodeName, fRate));
return;
}
if (fRate < m_fRevenueRate)
{
Util.Log(Util.LOG_TYPE.VERVOSE, string.Format("[DartAPI][영업실적] 당기순이익률 낮음({0}, {1}% / {2}%)", strCodeName, fRate, m_fRevenueRate));
return;
}
string strRef = "DartAPI";
string strTitle = string.Format("영업실적 - {0} {1:n2}%", strCodeName, fRate);
if ((Code.m_enType & CodeList.CODE_TYPE.DENIAL) == CodeList.CODE_TYPE.DENIAL)
Util.Log(Util.LOG_TYPE.DENIAL, string.Format("[{0}] {1}", strRef, strTitle));
else if ((Code.m_enType & CodeList.CODE_TYPE.DUPLICATED) == CodeList.CODE_TYPE.DUPLICATED)
Util.Log(Util.LOG_TYPE.DUPLICATED, string.Format("[{0}] {1}", strRef, strTitle));
else if ((Code.m_enType & CodeList.CODE_TYPE.MANUAL) == CodeList.CODE_TYPE.MANUAL)
{
Util.Log(Util.LOG_TYPE.MANUAL_CODE, string.Format("[{0}] {1}", strRef, strTitle));
if (m_bBuy == true)
{
ModelessPopup ManualPopup = new ModelessPopup(this);
ManualPopup.SetMessage(string.Format("{0}\n[{1}] {2}\n\n매수하시겠습니까?",
DateTime.Now.ToString("[hh:mm:ss]"),
strRef, strTitle), Code);
ManualPopup.TopMost = true;
ManualPopup.Show();
}
}
else
{
BuyItem(Code);
Util.Log(Util.LOG_TYPE.POSITIVE, string.Format("[{0}] {1}", strRef, strTitle));
}
m_CodeList.AddDuplicatedList(Code.m_strCode, Code.m_strName);
}
public void OnReceivedRightsIssue(string strCodeName)
{
CodeList.CODE_VALUE Code = m_CodeList.GetCodeByName(strCodeName);
if (Code == null)
{
Util.Log(Util.LOG_TYPE.VERVOSE, string.Format("[DartAPI][제3자배정증자] 종목을 찾을 수 없음({0})", strCodeName));
return;
}
string strRef = "DartAPI";
string strTitle = string.Format("제3자배정증자 - {0}", strCodeName);
if ((Code.m_enType & CodeList.CODE_TYPE.DENIAL) == CodeList.CODE_TYPE.DENIAL)
Util.Log(Util.LOG_TYPE.DENIAL, string.Format("[{0}] {1}", strRef, strTitle));
else if ((Code.m_enType & CodeList.CODE_TYPE.DUPLICATED) == CodeList.CODE_TYPE.DUPLICATED)
Util.Log(Util.LOG_TYPE.DUPLICATED, string.Format("[{0}] {1}", strRef, strTitle));
else if ((Code.m_enType & CodeList.CODE_TYPE.MANUAL) == CodeList.CODE_TYPE.MANUAL)
{
Util.Log(Util.LOG_TYPE.MANUAL_CODE, string.Format("[{0}] {1}", strRef, strTitle));
if (m_bBuy == true)
{
ModelessPopup ManualPopup = new ModelessPopup(this);
ManualPopup.SetMessage(string.Format("{0}\n[{1}] {2}\n\n매수하시겠습니까?",
DateTime.Now.ToString("[hh:mm:ss]"),
strRef, strTitle), Code);
ManualPopup.TopMost = true;
ManualPopup.Show();
}
}
else
{
BuyItem(Code);
Util.Log(Util.LOG_TYPE.POSITIVE, string.Format("[{0}] {1}", strRef, strTitle));
}
m_CodeList.AddDuplicatedList(Code.m_strCode, Code.m_strName);
}
public void OnSupplyContractRateChanged(float fRate)
{
m_fSupplyContractRate = fRate;
Config.SetSupplyContractRate(fRate);
}
public void OnRevenueRateChanged(float fRate)
{
m_fRevenueRate = fRate;
Config.SetRevenueRate(fRate);
}
public bool IsDuplicatedURL(string strURL)
{
if(strURL == "")

View File

@@ -1,6 +1,7 @@
manual-price=100000
buy-price=100000
supply-contract-rate=50
supply-contract-rate=15
revenue-rate=35.5
account=335261568
sub-account=10
dart-api-key1=840943e5370eb9037057beab35f4468fa9a6ce5c