void TimerTick(object sender, EventArgs e) { if (FormBorderStyle.Equals(FormBorderStyle.Sizable) && WindowState.Equals(FormWindowState.Minimized) == false && Result.Equals(DialogResult.Yes)) { FormBorderStyle = FormBorderStyle.FixedSingle; WindowState = FormWindowState.Minimized; } else if (DateTime.Now.Hour < 3 && backgroundWorker.IsBusy == false && DateTime.Now.DayOfWeek.Equals(DayOfWeek.Sunday) && (cookie as string).Equals(admin) == false) { timer.Stop(); strip.ItemClicked -= OnItemClick; GetSettleTheFare(); Dispose(); } else if (Visible == false && ShowIcon == false && notifyIcon.Visible && WindowState.Equals(FormWindowState.Minimized)) { notifyIcon.Icon = (Icon)resources.GetObject(Change ? upload : download); Change = !Change; if (IsApplicationAlreadyRunning(Privacy.Security) == false && backgroundWorker.IsBusy == false && string.IsNullOrEmpty(Privacy.Account) && string.IsNullOrEmpty(Privacy.SecuritiesAPI) && string.IsNullOrEmpty(Privacy.SecurityAPI)) { strip.Items.Find(st, false).First(o => o.Name.Equals(st)).PerformClick(); } } else { Statistical.CheckForSurvival(colors[DateTime.Now.Second % 3]); } }
void TimerTick(object sender, EventArgs e) { if (FormBorderStyle.Equals(FormBorderStyle.Sizable) && WindowState.Equals(FormWindowState.Minimized) == false) { WindowState = FormWindowState.Minimized; Visible = false; ShowIcon = false; notifyIcon.Visible = true; } else if (Visible == false && ShowIcon == false && notifyIcon.Visible && WindowState.Equals(FormWindowState.Minimized)) { var now = DateTime.Now; var sat = Base.CheckIfMarketDelay(now); now = now.DayOfWeek switch { DayOfWeek.Sunday => now.AddDays(1), DayOfWeek.Saturday => now.AddDays(2), DayOfWeek weeks when weeks.Equals(DayOfWeek.Friday) && now.Hour > (sat ? 9 : 8) => now.AddDays(3), _ => now.Hour > (sat ? 9 : 8) || Array.Exists(Base.Holidays, o => o.Equals(now.ToString(Base.DateFormat))) ? now.AddDays(1) : now, }; sat = Base.CheckIfMarketDelay(now); var remain = new DateTime(now.Year, now.Month, now.Day, sat ? 0xA : 9, 0, 0) - DateTime.Now; notifyIcon.Text = Base.GetRemainingTime(remain); if (API is null && Base.IsDebug is false && remain.TotalMinutes < 0x29 && now.Hour == (sat ? 9 : 8)) { API = new ConnectAPI(args); timer.Interval = 0x3A99; } else if (API is null && Base.IsDebug) { API = new ConnectAPI(administrator); timer.Interval = 0x3A99; }
async void BackgroundWorkerDoWork(object sender, DoWorkEventArgs e) { ISecuritiesAPI <SendSecuritiesAPI> connect = null; var catalog = new Dictionary <string, IStrategics>(); if (privacy.CodeStrategics is string cStrategics) { foreach (var strategics in cStrategics?.Split(';')) { var stParam = strategics?.Split('.'); if (Enum.TryParse(strategics.Substring(0, 2), out Strategics initial)) { switch (initial) { case Strategics.TF: if (int.TryParse(stParam[0].Substring(0xB), out int ds) & int.TryParse(stParam[1], out int dl) & int.TryParse(stParam[2], out int m) & int.TryParse(stParam[3], out int ms) & int.TryParse(stParam[4], out int ml) & int.TryParse(stParam[5], out int rs) & int.TryParse(stParam[6], out int rl) & int.TryParse(stParam[7], out int qs) & int.TryParse(stParam[8], out int ql)) { catalog[strategics.Substring(2, 8)] = new TrendFollowingBasicFutures { Code = strategics.Substring(2, 8), RollOver = stParam[0].Substring(0xA, 1).Equals("1"), DayShort = ds, DayLong = dl, Minute = m, MinuteShort = ms, MinuteLong = ml, ReactionShort = rs, ReactionLong = rl, QuantityShort = qs, QuantityLong = ql } } ; break; case Strategics.TS: if (char.TryParse(stParam[stParam.Length - 1], out char setting) && char.TryParse(stParam[8], out char tTrend) && char.TryParse(stParam[7], out char longShort) && int.TryParse(stParam[6], out int quoteUnit) && int.TryParse(stParam[5], out int quantity) && double.TryParse(stParam[4].Insert(stParam[4].Length - 2, "."), out double additionalPurchase) && double.TryParse(stParam[3].Insert(stParam[3].Length - 2, "."), out double realizeProfit) && int.TryParse(stParam[2], out int trend) && int.TryParse(stParam[1], out int l) && int.TryParse(stParam[0].Substring(8), out int s)) { catalog[strategics.Substring(2, 6)] = new TrendsInStockPrices { Code = strategics.Substring(2, 6), Short = s, Long = l, Trend = trend, RealizeProfit = realizeProfit * 0.01, AdditionalPurchase = additionalPurchase * 0.01, Quantity = quantity, QuoteUnit = quoteUnit, LongShort = (LongShort)longShort, TrendType = (Trend)tTrend, Setting = (Setting)setting } } ; break; } } } } switch (com) { case OpenAPI.ConnectAPI o: Stack = new Stack <string>(); double basePrice = double.MinValue; foreach (var code in o.InputValueRqData()) { if ((code.Length == 8 && (code.StartsWith("2") || code.StartsWith("3")) && double.TryParse(code.Substring(code.Length - 3), out double oPrice) && (oPrice > basePrice + 0x41 || oPrice < basePrice - 0x41)) == false) { if (code.Length == 8 && code.StartsWith("106")) { futures.Add(code); } else if (code.Length == 8 && code.StartsWith("101") && double.TryParse((await client.GetContext(new Codes { Code = code })).Price, out double price)) { basePrice = price; futures.Add(code); } Stack.Push(code); o.InputValueRqData(string.Concat(instance, code.Length == 8 ? opt50001 : optkwFID), code).Send += OnReceiveSecuritiesAPI; } } o.ConnectChapterOperation.Send += OnReceiveSecuritiesAPI; connect = o; break; case XingAPI.ConnectAPI x: foreach (var ctor in x.ConvertTheCodeToName) { ctor.Send += OnReceiveSecuritiesAPI; ctor.QueryExcute(); } if (catalog.Any(o => o.Key.Length == 8)) { foreach (var conclusion in x.Conclusion) { conclusion.OnReceiveRealTime(string.Empty); } } var alarm = x.JIF; alarm.Send += OnReceiveSecuritiesAPI; alarm.QueryExcute(); connect = x; break; } foreach (var kv in catalog.OrderByDescending(o => o.Key)) { if (connect.Strategics.Add(kv.Value) && connect?.SetStrategics(kv.Value) > 0) { switch (kv.Key.Length) { case int length when length == 8 && (kv.Key.StartsWith("101") || kv.Key.StartsWith("106")): foreach (var real in (connect as XingAPI.ConnectAPI)?.Reals) { real.OnReceiveRealTime(kv.Key); } break; } } } if (com is OpenAPI.ConnectAPI api && DateTime.Now.Hour == 8 && TimerBox.Show(info, si, MessageBoxButtons.OKCancel, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1, string.IsNullOrEmpty(privacy.CodeStrategics) ? 0x1FAC7U : (uint)(catalog.Count * 0x4BAF)).Equals(DialogResult.OK)) { Stocks = new Stack <string>(GetRevisedStockPrices(stocks)); var retention = await SelectDaysCodeAsync(); (api?.InputValueRqData(string.Concat(instance, opt10081), string.Concat(retention.Code, ';', retention.LastDate))).Send += OnReceiveSecuritiesAPI; } Connect = int.MaxValue; } void GoblinBatResize(object sender, EventArgs e) { if (WindowState.Equals(FormWindowState.Minimized)) { SuspendLayout(); Visible = false; ShowIcon = false; notifyIcon.Visible = true; if (strategy.Text.Equals(balance) && Balance != null) { Balance.Hide(); if (com is OpenAPI.ConnectAPI openAPI) { openAPI.OnConnectErrorMessage.Send -= OnReceiveSecuritiesAPI; openAPI.Send -= OnReceiveSecuritiesAPI; openAPI.InputValueRqData(false, opw00005).Send -= OnReceiveSecuritiesAPI; foreach (var ctor in openAPI.HoldingStocks) { Balance.SetDisconnectHoldingStock(ctor); ctor.SendBalance -= OnReceiveSecuritiesAPI; } } else if (com is XingAPI.ConnectAPI xing) { foreach (var ctor in xing.HoldingStocks) { Balance.SetDisconnectHoldingStock(ctor); ctor.SendBalance -= OnReceiveSecuritiesAPI; } foreach (var ctor in xing.querys) { ctor.Send -= OnReceiveSecuritiesAPI; } } } ResumeLayout(); } } void GoblinBatFormClosing(object sender, FormClosingEventArgs e) { GetSettleTheFare(); switch (MessageBox.Show(rExit, notifyIcon.Text, MessageBoxButtons.YesNoCancel, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button3)) { case DialogResult.Cancel: e.Cancel = true; WindowState = FormWindowState.Minimized; Application.DoEvents(); return; case DialogResult.Yes: int code = 0; Invoke(new Action(async() => code = await client.DeleteContext <Privacies>(privacy))); if (code > 0xC8) { SendMessage(OnReceiveErrorMessage(code)); } break; } timer.Stop(); strip.ItemClicked -= OnItemClick; Dispose(); } void TimerTick(object sender, EventArgs e) { if (com == null) { timer.Stop(); strip.ItemClicked -= OnItemClick; Dispose(); } else if (FormBorderStyle.Equals(FormBorderStyle.Sizable) && WindowState.Equals(FormWindowState.Minimized) == false) { for (int i = 0; i < GetTheCorrectAnswer.Length; i++) { var temp = 1 + random.Next(Connect, 0x4B0) * (i + 1); GetTheCorrectAnswer[i] = temp < 0x4B1 ? temp : 0x4B0 - i; } WindowState = FormWindowState.Minimized; } else if (Controls.Contains((Control)com) == false && WindowState.Equals(FormWindowState.Minimized)) { strip.Items.Find(st, false).First(o => o.Name.Equals(st)).PerformClick(); } else if (Visible && ShowIcon && notifyIcon.Visible == false && FormBorderStyle.Equals(FormBorderStyle.None) && WindowState.Equals(FormWindowState.Normal) && (com is XingAPI.ConnectAPI || com is OpenAPI.ConnectAPI)) { var now = DateTime.Now; int day = 0, today = DateTime.DaysInMonth(now.Year, now.Month); switch (now.DayOfWeek) { case DayOfWeek.Sunday: day = now.AddDays(1).Day; break; case DayOfWeek.Saturday: day = now.AddDays(2).Day; break; case DayOfWeek weeks when weeks.Equals(DayOfWeek.Friday) && now.Hour > 8: day = now.AddDays(3).Day; break; default: day = (now.Hour > 8 || Array.Exists(holidays, o => o.Equals(now.ToString(dFormat))) ? now.AddDays(1) : now).Day; break; } var remain = new DateTime(now.Year, now.Day == today ? now.AddMonths(1).Month : now.Month, day, 9, 0, 0) - DateTime.Now; com.SetForeColor(colors[DateTime.Now.Second % 3], GetRemainingTime(remain)); if (remain.TotalMinutes < 0x1F && com.Start == false && DateTime.Now.Hour == 8 && DateTime.Now.Minute > 0x1E && (Connect > 0x4B0 || Array.Exists(GetTheCorrectAnswer, o => o == random.Next(Connect++, 0x4B1)))) { com.StartProgress(); } } else if (Visible == false && ShowIcon == false && notifyIcon.Visible && WindowState.Equals(FormWindowState.Minimized)) { notifyIcon.Icon = (Icon)resources.GetObject(icon[DateTime.Now.Second % 4]); } } void OnItemClick(object sender, ToolStripItemClickedEventArgs e) => BeginInvoke(new Action(() => { if (e.ClickedItem.Name.Equals(st)) { SuspendLayout(); if (strategy.Text.Equals(balance) && Balance != null) { if (com is XingAPI.ConnectAPI xingAPI) { foreach (var ctor in xingAPI.querys) { ctor.Send += OnReceiveSecuritiesAPI; ctor.QueryExcute(); } foreach (var ctor in xingAPI.HoldingStocks) { Balance.SetConnectHoldingStock(ctor); ctor.SendBalance += OnReceiveSecuritiesAPI; } if (Connect == int.MaxValue) { foreach (var convert in xingAPI.ConvertTheCodeToName) { convert.Send -= OnReceiveSecuritiesAPI; } } } else if (com is OpenAPI.ConnectAPI openAPI) { openAPI.OnConnectErrorMessage.Send += OnReceiveSecuritiesAPI; openAPI.Send += OnReceiveSecuritiesAPI; openAPI.InputValueRqData(true, opw00005).Send += OnReceiveSecuritiesAPI; foreach (var ctor in openAPI.HoldingStocks) { Balance.SetConnectHoldingStock(ctor); ctor.SendBalance += OnReceiveSecuritiesAPI; } if (Connect == int.MaxValue) { while (Stack.Count > 0) { var pop = Stack.Pop(); openAPI.InputValueRqData(pop.Length == 8 ? opt50001 : optkwFID, pop).Send -= OnReceiveSecuritiesAPI; } } } Connect = int.MinValue; Size = new Size(0x3B8, 0x63 + 0x28); Balance.Show(); } Visible = true; ShowIcon = true; notifyIcon.Visible = false; WindowState = FormWindowState.Normal; ResumeLayout(); if (com is XingAPI.ConnectAPI xing && xing.API == null || com is OpenAPI.ConnectAPI open && open.API == null) { StartProgress(); } } else { Close(); } })); IEnumerable <string> GetRevisedStockPrices(List <string> list) { int index, start, end; var stocks = new Stack <string>(); switch (DateTime.Now.Second % 5) { case 0: start = 0; end = 0x3E8; break; case 1: start = 0x2EE; end = 0x6D6; break; case 2: start = 0x5DC; end = 0x9C4; break; case 3: start = 0; end = list.Count; break; default: start = list.Count - 0x3E9; end = list.Count; break; } for (index = start; index < end; index++) { stocks.Push(list[index]); } return(stocks.OrderBy(o => Guid.NewGuid())); } string SelectFuturesCode { get { var code = string.Empty; while (futures.Count > 0 && string.IsNullOrEmpty(code)) { code = futures[random.Next(0, futures.Count)]; } return(code); } } async Task <Retention> SelectOptionsCodeAsync() { if (options.Count > 0) { var retention = await client.GetContext(options[random.Next(0, options.Count)]); if (options.Remove(retention.Code)) { if (string.IsNullOrEmpty(retention.LastDate) == false && retention.LastDate.Substring(0, 6).Equals(DateTime.Now.ToString("yyMMdd"))) { return(await SelectOptionsCodeAsync()); } else if (string.IsNullOrEmpty(retention.Code) == false && retention.LastDate == null) { return(await SelectOptionsCodeAsync()); } else if (com is XingAPI.ConnectAPI && string.IsNullOrEmpty(retention.Code) == false && string.IsNullOrEmpty(retention.LastDate)) { return(await SelectStocksCodeAsync()); } else { return(retention); } } else { return(await SelectOptionsCodeAsync()); } } else { return new Retention { Code = null, LastDate = null } }; } async Task <Retention> SelectStocksCodeAsync() { if (stocks.Count > 0) { var retention = await client.GetContext(stocks[random.Next(0, stocks.Count)]); if (stocks.Remove(retention.Code)) { if (string.IsNullOrEmpty(retention.LastDate) == false && retention.LastDate.Substring(0, 6).Equals(DateTime.Now.ToString("yyMMdd"))) { return(await SelectStocksCodeAsync()); } else if ((await client.GetContext(new Codes { Code = retention.Code })).MaturityMarketCap.Contains("거래정지")) { return(await SelectStocksCodeAsync()); } else if (string.IsNullOrEmpty(retention.Code) == false && retention.LastDate == null) { return(await SelectStocksCodeAsync()); } else if (com is XingAPI.ConnectAPI && string.IsNullOrEmpty(retention.Code) == false && string.IsNullOrEmpty(retention.LastDate)) { return(await SelectStocksCodeAsync()); } else { for (int i = 0; i < retention.Code.Length / 3; i++) { var status = await client.PostContext(await consensus.GetContextAsync(i, retention.Code)); SendMessage(status); } return(retention); } } else { return(await SelectStocksCodeAsync()); } } else { return new Retention { Code = null, LastDate = null } }; } async Task <Retention> SelectDaysCodeAsync() { if (Stocks.Count > 0) { var code = Stocks.Pop(); SendMessage(string.Concat(Stocks.Count + "/" + stocks.Count + "\tCode_" + code)); var date = DateTime.Now; if (string.IsNullOrEmpty(code) == false) { return new Retention { Code = code, LastDate = (date.Hour < 6 ? date.AddDays(-1) : date).ToString("yyyyMMdd") } } ; else { return(await SelectDaysCodeAsync()); } } else { return(new Retention()); } } void Dispose(FormWindowState state) { GetSettleTheFare(); if (state.Equals(FormWindowState.Minimized) == false) { WindowState = FormWindowState.Minimized; } switch (com) { case OpenAPI.ConnectAPI o: o.ConnectChapterOperation.Send -= OnReceiveSecuritiesAPI; break; case XingAPI.ConnectAPI x: x.JIF.Send -= OnReceiveSecuritiesAPI; break; } if (timer.Enabled) { timer.Stop(); } strip.ItemClicked -= OnItemClick; Dispose(); }