private void Socket_OnDataLastPrice(MessGet data) { var market = (data as MessGetLastPrice)?.Key?.MarketName; var pair = (data as MessGetLastPrice)?.Key?.Pair; var last_price = new ValueLastPrice { Data = (data as MessGetLastPrice)?.Value }; // exists or new tab var page_name = market + " " + pair + " Last price"; var page = FindOrAddTab(page_name); market = EnumValue.GetEnum <MarketType>(market).ToString(); var text_box_name = "rtb" + market + pair + "Last_price"; RichTextBox text_box = FindOrAddControl(text_box_name, page); try { this.BeginInvoke((Action)(() => { text_box.Clear(); text_box.Text += "Update time: " + DateTime.Now.ToString() + "\n"; text_box.Text += JsonConvert.SerializeObject(last_price) + "\n"; })); } catch { } }
/// <summary> /// Update markets list on form /// </summary> private void UpdateMarkets(List <string> markets) { // subs to all markets if (smart_subs) { smart_subs = false; foreach (var item in markets) { var market = EnumValue.GetEnum <MarketType>(item); if (rbReal.Checked) { socket?.Send(Subs.Balance(SubsType.SubsAndGetNextChange, market)); } socket?.Send(Subs.Orders(SubsType.SubsAndGetExist, market, rbReal.Checked ? SysType.Real : SysType.Demo)); socket?.Send(Subs.Deals(SubsType.SubsAndGetExist, market, rbReal.Checked ? SysType.Real : SysType.Demo)); } } try { this.BeginInvoke((Action)(() => { lbKeysTime.Text = DateTime.Now.ToString(); // load markets lbMarkets.Items.Clear(); lbMarkets.Items.AddRange(markets.ToArray()); })); } catch { } }
private void Socket_OnDataRecentTrades(MessGet data) { var market = (data as MessGetRecentTrades)?.Key?.MarketName; var pair = (data as MessGetRecentTrades)?.Key?.Pair; var recent_trades = (data as MessGetRecentTrades)?.Value; // exists or new tab var page_name = market + " " + pair + " Recent trades"; var page = FindOrAddTab(page_name); market = EnumValue.GetEnum <MarketType>(market).ToString(); var text_box_name = "rtb" + market + pair + "Recent_trades"; RichTextBox text_box = FindOrAddControl(text_box_name, page); try { this.BeginInvoke((Action)(() => { text_box.Clear(); text_box.Text += "Update time: " + DateTime.Now.ToString() + "\n"; foreach (var item in recent_trades) { text_box.Text += JsonConvert.SerializeObject(item) + "\n"; } })); } catch { } }
private void Socket_OnDataPairsDetail(MessGet data) { var market = (data as MessGetPairsDetail)?.Key?.MarketName; var pairs_detail = (data as MessGetPairsDetail)?.Value; // exists or new tab var page_name = market + " Pairs configuration"; var page = FindOrAddTab(page_name); market = EnumValue.GetEnum <MarketType>(market).ToString(); var text_box_name = "rtb" + market + "Pairs_configuration"; RichTextBox text_box = FindOrAddControl(text_box_name, page); try { this.BeginInvoke((Action)(() => { text_box.Clear(); text_box.Text += "Update time: " + DateTime.Now.ToString() + "\n"; foreach (var item in pairs_detail) { text_box.Text += JsonConvert.SerializeObject(item) + "\n"; } })); } catch { } }
private MarketType GetMarket() { if (lbMarkets.SelectedItem == null) { MessageBox.Show("No Markets selected", "Warning"); return(MarketType.Empty); } return(EnumValue.GetEnum <MarketType>(lbMarkets.SelectedItem.ToString())); }
private MarketType GetMarket(bool no_message = false) { if (lbMarkets.SelectedItem == null) { if (!no_message) { MessageBox.Show("No Markets selected", "Warning"); } return(MarketType.Empty); } string market = lbMarkets.SelectedItem.ToString(); return(EnumValue.GetEnum <MarketType>(market)); }
private void Socket_OnDataOrderbook(MessGet data) { var market = (data as MessGetOrderbook)?.Key?.MarketName; var pair = (data as MessGetOrderbook)?.Key?.Pair; var orderbook = (data as MessGetOrderbook)?.Value; // exists or new tab var page_name = market + " " + pair + " Orderbook"; var page = FindOrAddTab(page_name); market = EnumValue.GetEnum <MarketType>(market).ToString(); var text_box_name = "rtb" + market + pair + "Orderbook"; RichTextBox text_box = FindOrAddControl(text_box_name, page); try { this.BeginInvoke((Action)(() => { text_box.Clear(); text_box.Text += "Update time: " + DateTime.Now.ToString() + "\n"; if (orderbook?.ASKs == null) { text_box.Text += "ASKs: NULL\n"; } else { text_box.Text += "ASKs:\n"; foreach (var item in orderbook.ASKs) { text_box.Text += "price=" + item.Key + ", amount=" + item.Value + "\n"; } } if (orderbook?.BIDs == null) { text_box.Text += "BIDs: NULL\n"; } else { text_box.Text += "BIDs:\n"; foreach (var item in orderbook.BIDs) { text_box.Text += "price=" + item.Key + ", amount=" + item.Value + "\n"; } } })); } catch { } }
/// <summary> /// Get user's balances /// </summary> /// <param name="type">Type of system</param> public Dictionary <MarketType, DataBalances> GetBalances(SysType type) { Dictionary <MarketType, DataBalances> result = null; // check params if (type == SysType.Empty) { throw new ArgumentNullException("type"); } // request formation var request = type == SysType.Real ? new Request(MethodType.Balances) : new Request(MethodType.DemoBalances); request.Prepare(public_key, private_key); // request execution var response = ExecQuery(request); // response analysis if (response.IsSuccessfully) { result = new Dictionary <MarketType, DataBalances>(); var data = (response.ResponseObject as ResponseBalances)?.Data; // fill result foreach (var item in data) { string market_name = item.Key; market_name = market_name.Replace(demo, string.Empty); var market = EnumValue.GetEnum <MarketType>(market_name); if (market == MarketType.Empty) { logger.Error("Undeclared market value: {0}", item.Key); } else { result.Add(market, item.Value); } } } return(result); }
private void Socket_OnDataBalances(MessGet data) { balances = new Dictionary <MarketType, DataBalances>(); // convert market var dict = (data as MessGetBalances)?.Value; if (dict != null) { foreach (var item in dict) { string market_name = item.Key; market_name = market_name.Replace(SKey.demo, string.Empty); var market = EnumValue.GetEnum <MarketType>(market_name); if (market == MarketType.Empty) { logger.Error("Undeclared market value: {0}", item.Key); } else { balances.Add(market, item.Value); } } } try { this.BeginInvoke((Action)(() => { lbBalance.Text = "Update time: " + DateTime.Now.ToString(); })); } catch { } if ((data as MessGetBalances)?.Key.SysType == SysType.Demo) { UpdateMarkets(balances?.Keys.Select(x => EnumValue.GetValue(x)).ToList()); } UpdateBalances(); }
private void Socket_OnDataBoxState(MessGet data) { api_keys = new Dictionary <MarketType, DataAPIKey>(); // convert market var dict = (data as MessGetBoxState)?.Value; foreach (var item in dict) { var market = EnumValue.GetEnum <MarketType>(item.Key); if (market == MarketType.Empty) { logger.Error("Undeclared market value: {0}", item.Key); } else { api_keys.Add(market, item.Value); } } UpdateMarkets(api_keys?.Keys.Select(x => EnumValue.GetValue(x)).ToList()); }
private void Socket_OnDataPriceByTime(MessGet data) { var market = (data as MessGetPriceByTime)?.Key?.MarketName; var pair = (data as MessGetPriceByTime)?.Key?.Pair; var price = (data as MessGetPriceByTime)?.Value?.Price; // exists or new tab var page_name = market + " " + pair + " Historical price"; var page = FindOrAddTab(page_name); market = EnumValue.GetEnum <MarketType>(market).ToString(); var text_box_name = "rtb" + market + pair + "Historical_price"; RichTextBox text_box = FindOrAddControl(text_box_name, page); try { this.BeginInvoke((Action)(() => { text_box.Text += "Update time: " + DateTime.Now.ToString() + " " + EnumValue.GetValue((data as MessGetPriceByTime).Key.Proc) + " " + price + "\n"; })); } catch { } }
/// <summary> /// Get a list of markets and pairs /// </summary> public Dictionary <MarketType, List <string> > GetMarketsPairs() { Dictionary <MarketType, List <string> > result = null; // request formation var request = new Request(MethodType.MarketsPairs); request.Prepare(public_key, private_key); // request execution var response = ExecQuery(request); // response analysis if (response.IsSuccessfully) { result = new Dictionary <MarketType, List <string> >(); var data = (response.ResponseObject as ResponseMarketsPairs)?.Data; // fill result foreach (var item in data) { var market = EnumValue.GetEnum <MarketType>(item.Key); if (market == MarketType.Empty) { logger.Error("Undeclared market value: {0}", item.Key); } else { result.Add(market, item.Value); } } } return(result); }