void OnEventConnect(object sender, _DKHOpenAPIEvents_OnEventConnectEvent e) { SendErrorMessage(e.nErrCode); Code = API.GetFutureCodeByIndex(e.nErrCode); RemainingDay(Code); CodeList = new List <string> { Code }; if (DateTime.Now.Hour > 4 && (DateTime.Now.Hour < 15 || DateTime.Now.Hour == 15 && DateTime.Now.Minute < 45) && (DateTime.Now.DayOfWeek.Equals(DayOfWeek.Saturday) || DateTime.Now.DayOfWeek.Equals(DayOfWeek.Sunday)) == false) { if (Temporary == null) { PrepareForTrading(API.GetLoginInfo("ACCLIST")); } DeadLine = DateTime.Now.Hour < 9 ? false : true; } else if (Temporary != null) { OnCollectingData(GetInformation()); } SendCount?.Invoke(this, new NotifyIconText((byte)e.nErrCode)); }
public Class1() { SendCount del = new SendCount(Count); del2 = new SendCount(Log); del += del2 + new SendCount(MoreStuff); doWork(del); }
void PrepareForTrading(string account) { SendCount?.Invoke(this, new NotifyIconText(account, API.GetLoginInfo("USER_ID"), API.GetLoginInfo("USER_NAME"), API.GetLoginInfo("GetServerGubun"))); SellOrder = new Dictionary <string, double>(); BuyOrder = new Dictionary <string, double>(); Trend = new Dictionary <string, string>(); LookUpTheDeposit(account.Split(';')); LookUpTheBalance(account.Split(';')); SetPasswordWhileCollectingData(5971); OnReceiveBalance = DateTime.Now.Hour > 8 ? true : false; }
void OnReceiveMsg(object sender, _DKHOpenAPIEvents_OnReceiveMsgEvent e) { if (Array.Exists(basic, o => o.Equals(e.sMsg.Substring(9)))) { var temp = e.sMsg.Substring(9); if ((temp.Equals(basic[2]) || temp.Equals(basic[6]) || temp.Equals(basic[8])) && OnReceiveBalance == false) { OnReceiveBalance = request.QueueCount == 0 ? true : false; } if (e.sMsg.Contains("모의투자")) { temp = temp.Replace("모의투자 ", string.Empty); } if (e.sMsg.Last().Equals('다') || e.sMsg.Last().Equals('요')) { temp = string.Concat(temp, "."); } SendState?.Invoke(this, new State(OnReceiveBalance, SellOrder.Count, Quantity, BuyOrder.Count, ScreenNumber)); SendCount?.Invoke(this, new NotifyIconText(temp)); return; } if (e.sMsg.Equals(TR)) { SendMemorize?.Invoke(this, new Memorize("Clear")); Request(GetRandomCode(new Random().Next(0, CodeList.Count))); return; } if (e.sMsg.Equals(Failure)) { Process.Start("shutdown.exe", "-r"); Dispose(); return; } if (e.sMsg.Contains(Response) && TimerBox.Show(string.Concat(Response, "."), GoblinBat, MessageBoxButtons.OKCancel, MessageBoxIcon.Information, MessageBoxDefaultButton.Button2, 1375).Equals(DialogResult.OK)) { return; } if (e.sMsg.Substring(9).Equals(LookUp)) { return; } new ExceptionMessage(e.sMsg); }
void SendErrorMessage(int error) { if (error < 0) { new ExceptionMessage(this.error.GetErrorMessage(error)); switch (error) { case -100: case -101: case -102: case -200: Process.Start("shutdown.exe", "-r"); Dispose(); return; case -106: SendCount?.Invoke(this, new NotifyIconText(error)); break; case -300: SendMemorize?.Invoke(this, new Memorize("Clear")); Request(GetRandomCode(new Random().Next(0, CodeList.Count))); return; default: return; } if (API != null) { API = null; } if (OpenAPI != null) { OpenAPI = null; } } }
void Request(string code) { if (code != null && code.Equals(string.Empty) == false) { int param = DeadLine ? 4 : (code.Length > 6 ? (code.Substring(5, 3).Equals("000") ? 1 : 2) : 3); ITRs tr = (ITRs)catalogTR[param]; tr.Value = code; tr.RQName = string.Concat(code, ";", GetRetention(param, code)); tr.PrevNext = 0; request.RequestTrData(new Task(() => { InputValueRqData(tr); SendCount?.Invoke(this, new NotifyIconText(CodeList.Count, code)); })); return; } else if (CodeList.Count < 50) { foreach (var str in CodeList) { if (str == null || str.Equals(string.Empty)) { CodeList.Remove(str); } } } if (CodeList.Count == 0) { SendCount?.Invoke(this, new NotifyIconText(CodeList.Count, code)); CodeList = null; GC.Collect(); return; } Request(GetRandomCode(new Random().Next(0, CodeList.Count))); }
void OnReceiveRealData(object sender, _DKHOpenAPIEvents_OnReceiveRealDataEvent e) { var sb = new StringBuilder(512); int index = Array.FindIndex(Enum.GetNames(typeof(RealType)), o => o.Equals(e.sRealType)); if (index < 0) { return; } foreach (int fid in catalogReal[index]) { sb.Append(API.GetCommRealData(e.sRealKey, fid)).Append(';'); } var param = sb.ToString().Split(';'); switch (index) { case 0b1: if (e.sRealKey.Equals(Code)) { SendDatum?.Invoke(this, new Datum(param)); SendTrend?.Invoke(this, new Trends(Trend, Volume)); } return; case 0b10: if (e.sRealKey.Equals(Code)) { SendQuotes?.Invoke(this, new Quotes(new string[] { param[35], param[27], param[19], param[11], param[3], param[7], param[15], param[23], param[31], param[39] }, new string[] { param[36], param[28], param[20], param[12], param[4], param[8], param[16], param[24], param[32], param[40] }, new string[] { param[38], param[30], param[22], param[14], param[6], param[10], param[18], param[26], param[34], param[42] }, param[0], SellOrder, BuyOrder, string.Concat(param[44], ";", param[47]))); } return; case 0b1000: if (e.sRealKey.Equals(Code)) { SendCurrent?.Invoke(this, new Current(Quantity, param)); } return; case 0b1001: if (param[0].Equals("e") && DeadLine) { DeadLine = false; if (Temporary != null) { Temporary.SetStorage(Code); SendCount?.Invoke(this, new NotifyIconText(-106)); } else { OnReceiveBalance = false; } } else if (param[0].Equals("3") && DeadLine == false) { DeadLine = true; Delay.Milliseconds = 205; if (Temporary == null || Collector) { OnReceiveBalance = true; } } break; case 0xA: SendStocksDatum?.Invoke(this, new Stocks(e.sRealKey, param)); return; case 0xB: SendStocksQuotes?.Invoke(this, new StocksQuotes(e.sRealKey, param[0b100]));
private void OnReceiveData(string szTrCode) { Sb = new StringBuilder(128); foreach (var block in Array.Find(catalog, o => o.ToString().Contains(szTrCode.Substring(1))).GetOutBlock(Query.GetResData())) { for (int i = 0; i < Query.GetBlockCount(block.Name); i++) { Sb.Append(Query.GetFieldData(block.Name, block.Field, i)).Append(';'); } } switch (szTrCode) { case "t9943": foreach (var str in Sb.ToString().Split(';')) { if (str.Substring(0, 3).Equals("101")) { new Secret(str); SendCount?.Invoke(this, new NotifyIconText(Query.GetAccountName(Secret.Account), Query.GetAcctDetailName(Secret.Account), Query.GetAcctNickname(Secret.Account), str)); SellOrder = new Dictionary <string, double>(); BuyOrder = new Dictionary <string, double>(); Trend = new Dictionary <string, string>(); Real = new Dictionary <string, XARealClass>(); Total = new Queue <string>(); if (Query.LoadFromResFile(string.Concat(Path, "t2105.res"))) { foreach (var block in new T2105().GetInBlock(Query.GetResData())) { Query.SetFieldData(block.Name, block.Field, block.Occurs, block.Property); } Delay.delay = 1000 / Query.GetTRCountPerSec("t2105"); request.RequestTrData(new Task(() => SendErrorMessage(Query.Request(false)))); } if (TimerBox.Show(Secret.OnReceiveData, Secret.GoblinBat, MessageBoxButtons.OK, MessageBoxIcon.Information, 13579).Equals(DialogResult.OK)) { foreach (var kv in real) { SetAPI(kv); } LookUpTheBalance(); SendCount?.Invoke(this, new NotifyIconText(7)); } return; } } return; case "t2105": LookUpTheDeposit(); var quotes = Sb.ToString().Split(';'); Name = quotes[0]; SendQuotes?.Invoke(this, new Quotes(new string[] { quotes[32], quotes[26], quotes[20], quotes[14], quotes[8], quotes[9], quotes[15], quotes[21], quotes[27], quotes[33] }, new string[] { quotes[34], quotes[28], quotes[22], quotes[16], quotes[10], quotes[11], quotes[17], quotes[23], quotes[29], quotes[35] }, new string[] { quotes[36], quotes[30], quotes[24], quotes[18], quotes[12], quotes[13], quotes[19], quotes[25], quotes[31], quotes[37] }, quotes[42], SellOrder, BuyOrder, string.Empty)); return; case "CFOBQ10500": var temp = Sb.ToString().Split(';'); SendDeposit?.Invoke(this, new Deposit(new string[] { temp[5], temp[6], temp[7], temp[14], temp[15], string.Empty, temp[16], temp[17], string.Empty, temp[18], temp[19], string.Empty, temp[23], temp[20], temp[21], temp[11], temp[12], temp[13], temp[8], temp[9], temp[24], string.Empty, temp[10], string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, string.Empty })); return; case "t0441": if (Query.IsNext) { Console.WriteLine(Secret.Account + "\t" + Sb); var bal = Sb.ToString().Split(';'); SendBalance?.Invoke(this, new Balance(new string[] { bal[10], Name, bal[11], bal[12], bal[14], bal[19], bal[21], bal[13], bal[15], bal[20] })); } else { var cts = Sb.ToString().Split(';'); if (cts[1].Equals(string.Empty) && cts[2].Equals(string.Empty)) { return; } new Secret(cts[1], cts[2]); foreach (var block in new T0441().GetInBlock(Query.GetResData())) { Query.SetFieldData(block.Name, block.Field, block.Occurs, block.Property); } Delay.delay = 1000 / Query.GetTRCountPerSec("t0441"); request.RequestTrData(new Task(() => SendErrorMessage(Query.Request(true)))); } return; } }
public void doWork(SendCount del) { del(0); del -= del2; del(5); }
void Dispose() { new Task(() => SendCount?.Invoke(this, new NotifyIconText((char)69))).Start(); Dispose(true); }