- elk update

- 모의투자
This commit is contained in:
2018-06-07 15:35:31 +09:00
parent 1712ac7b9b
commit d074af571a
10 changed files with 228 additions and 60 deletions

View File

@@ -1,4 +1,5 @@
using System;
using Newtonsoft.Json.Linq;
using System;
using System.Collections;
using System.Collections.Concurrent;
using System.Collections.Generic;
@@ -9,6 +10,7 @@ using System.Globalization;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Net.NetworkInformation;
using System.Text;
using System.Text.RegularExpressions;
@@ -819,8 +821,13 @@ namespace NewsCrawler
return;
string strCodeName = lvList.SelectedItems[0].SubItems[chCodeName.Index].Text;
string strTitle = lvList.SelectedItems[0].SubItems[chTitle.Index].Text;
CodeList.CODE_VALUE Code = m_CodeList.GetCodeByName(strCodeName);
m_CybosHelper.Buy(Code, Config.GetBuyPrice());
if (Code == null)
Code = m_CodeList.SearchCode(strTitle);
if (Code != null)
ProcessSearchAndBuy(new NEWS_ITEM(-1, strTitle, Code.m_strCode, Code, DateTime.Now, DateTime.Now, "", "", 0));
}
public void OnConfigFormClosing()
@@ -872,6 +879,94 @@ namespace NewsCrawler
Util.Clear();
}
public class HttpResult
{
public HttpStatusCode StatusCode;
public string strData;
};
async Task<HttpResult> Request(string url, HttpMethod method,
string data = null,
Dictionary<string, string> headers = null)
{
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
req.Method = method.ToString();
req.ContentType = "application/json";
if(headers != null)
{
foreach (var kv in headers)
req.Headers[kv.Key] = kv.Value;
}
if (data != null)
{
Stream writeStream = req.GetRequestStream();
byte[] buffer = Encoding.UTF8.GetBytes(data);
await writeStream.WriteAsync(buffer, 0, buffer.Length);
}
HttpWebResponse resp = null;
HttpResult result = null;
try
{
resp = await req.GetResponseAsync() as HttpWebResponse;
}
catch (WebException ex)
{
if (ex.Status == WebExceptionStatus.ProtocolError)
resp = ex.Response as HttpWebResponse;
}
finally
{
Stream readStream = resp.GetResponseStream();
StreamReader sr = new StreamReader(readStream);
result = new HttpResult()
{
StatusCode = resp.StatusCode,
strData = await sr.ReadToEndAsync()
};
}
return result;
}
async void SendConfiguration()
{
var oData = new
{
Mac = NetworkInterface.GetAllNetworkInterfaces()[0].GetPhysicalAddress().ToString(),
Date = DateTime.Now.ToString("yyyy-MM-dd"),
Config = Config.GetAllConfig(),
Keywords = new
{
Positive = m_Condition.GetAllPositive(),
PositiveForce = m_Condition.GetAllPositiveForce(),
Negative = m_Condition.GetAllNegative(),
Manual = m_Condition.GetAllManual(),
Duplicated = m_Condition.GetAllDuplicated(),
},
Codes = new
{
Deny = m_CodeList.GetAllDeny(),
Duplicated = m_CodeList.GetAllDuplicated(),
Manual = m_CodeList.GetAllManual(),
},
Synonym = m_CodeList.GetAllSynonym(),
};
string serverURL = "http://mjjo53.us.to:9200";
string index = "trading-news";
string doc = "default";
string id = $"{oData.Mac}-{oData.Date}";
JObject data = JObject.FromObject(oData);
string json = data.ToString(Newtonsoft.Json.Formatting.Indented);
Dictionary<string, string> headers = new Dictionary<string, string>();
headers["Authorization"] = "Basic dHJhZGVyOnNidG1hb2Fv";
var result = await Request($"{serverURL}/{index}/{doc}/{id}?pretty", HttpMethod.Post, json, headers);
}
private void chBuy_CheckedChanged(object sender, EventArgs e)
{
m_bBuy = chBuy.Checked;
@@ -885,10 +980,12 @@ namespace NewsCrawler
if (m_bBuy == true)
{
FileTransfer ft = new FileTransfer();
string today = DateTime.Now.ToString("yyyy-MM-dd");
string macAddr = NetworkInterface.GetAllNetworkInterfaces()[0].GetPhysicalAddress().ToString();
ft.SendDir("/configure", macAddr + "/NewsCrawler/" + today);
//FileTransfer ft = new FileTransfer();
//string today = DateTime.Now.ToString("yyyy-MM-dd");
//string macAddr = NetworkInterface.GetAllNetworkInterfaces()[0].GetPhysicalAddress().ToString();
//ft.SendDir("/configure", macAddr + "/NewsCrawler/" + today);
SendConfiguration();
Util.Log(Util.LOG_TYPE.VERVOSE, "매수 시작");
}