/// <summary> /// takes messages from the shared queue, converts them to C# classes, and sends them to up /// берет сообщения из общей очереди, конвертирует их в классы C# и отправляет на верх /// </summary> public void Converter() { while (true) { try { if (_isDisposed) { return; } if (!_newMessage.IsEmpty) { string data; if (_newMessage.TryDequeue(out data)) { if (data.StartsWith("<pits>") || data.StartsWith("<sec_info")) { continue; } if (data.StartsWith("<server_status")) { ServerStatus status = Deserialize <ServerStatus>(data); if (status.Connected == "true") { IsConnected = true; Connected?.Invoke(); } else if (status.Connected == "false") { IsConnected = false; Disconnected?.Invoke(); } else if (status.Connected == "error") { SendLogMessage(status.Text, LogMessageType.Error); } } else if (data.StartsWith("<securities>")) { var securities = _deserializer.Deserialize <List <Security> >(new RestResponse() { Content = data }); UpdatePairs?.Invoke(securities); } else if (data.StartsWith("<united_portfolio")) { UnitedPortfolio unitedPortfolio = Deserialize <UnitedPortfolio>(data); UpdatePortfolio?.Invoke(unitedPortfolio); } else if (data.StartsWith("<positions")) { var positions = Deserialize <TransaqPositions>(data); UpdatePositions?.Invoke(positions); } else if (data.StartsWith("<clientlimits")) { var limits = Deserialize <Clientlimits>(data); UpdateMonoPortfolio?.Invoke(limits); } else if (data.StartsWith("<client")) { var clientInfo = _deserializer.Deserialize <Client>(new RestResponse() { Content = data }); ClientsInfo?.Invoke(clientInfo); } else if (data.StartsWith("<alltrades>")) { var allTrades = _deserializer.Deserialize <List <Trade> >(new RestResponse() { Content = data }); NewTradesEvent?.Invoke(allTrades); } else if (data.StartsWith("<quotes>")) { var quotes = _deserializer.Deserialize <List <Quote> >(new RestResponse() { Content = data }); UpdateMarketDepth?.Invoke(quotes); } else if (data.StartsWith("<orders>")) { var orders = _deserializer.Deserialize <List <Order> >(new RestResponse() { Content = data }); MyOrderEvent?.Invoke(orders); } else if (data.StartsWith("<trades>")) { var myTrades = _deserializer.Deserialize <List <Trade> >(new RestResponse() { Content = data }); MyTradeEvent?.Invoke(myTrades); } else if (data.StartsWith("<candles")) { Candles newCandles = Deserialize <Candles>(data); NewCandles?.Invoke(newCandles); } else if (data.StartsWith("<messages>")) { if (data.Contains("Время действия Вашего пароля истекло")) { NeedChangePassword?.Invoke(); } } } } } catch (Exception exception) { SendLogMessage(exception.ToString(), LogMessageType.Error); } Thread.Sleep(1); } }
/// <summary> /// обновился стакан и тики /// </summary> private void SessionOnMarketDataChanged(OrderBookEvent orderBook) { UpdateMarketDepth?.Invoke(orderBook); }