private void InvokeMessageReceived(string channelName, string requestType, string message) { MessageType messageType = GetMessageType(requestType); switch (messageType) { case MessageType.OrderData: var orderMarketInfo = MarketInfo.ParseMarketInfo(channelName); var orders = Helper.ToEntity <OrderResponse>(message); OnOrderMessage?.Invoke(orderMarketInfo.Exchange, orderMarketInfo.PrimaryCurrency, orderMarketInfo.SecondaryCurrency, orders.OrderData.Orders); break; case MessageType.TradeData: var tradeMarketInfo = MarketInfo.ParseMarketInfo(channelName); var trade = Helper.ToEntity <TradeResponse>(message); OnTradeMessage?.Invoke(tradeMarketInfo.Exchange, tradeMarketInfo.PrimaryCurrency, tradeMarketInfo.SecondaryCurrency, trade.TradeData.Trade); break; case MessageType.BlockData: var blockInfo = BlockItem.ParseBlockInfo(channelName); OnBlockMessage?.Invoke(blockInfo, new BlockItem()); break; case MessageType.FavoriteData: var favourites = Helper.ToEntity <FavoriteResponse>(message); OnFavoriteMessage?.Invoke(favourites.Data.FavoritesDataData.Favorites); break; case MessageType.NotificationData: var notification = Helper.ToEntity <NotificationResponse>(message); OnNotificationMessage?.Invoke(notification.NotificationData.NotificationDataData.NotificationDataItem); break; case MessageType.NewsData: var news = Helper.ToEntity <NewsResponse>(message); OnNewsMessage?.Invoke(news.NewsData.NewsDataItem); break; case MessageType.NewMarket: var newMarket = Helper.ToEntity <NewMarketResponse>(message); OnNewMarketMessage?.Invoke(newMarket.NewMarketData.NewMarketDataItem); break; } OnMessage?.Invoke(messageType, message); }
private void InvokeMessageReceived(string channelName, string requestType, string message) { // Determine the message type using the function we previously created MessageType messageType = GetMessageType(requestType); switch (messageType) { case MessageType.TradeData: // Parse the channel name var tradeMarketInfo = MarketInfo.ParseMarketInfo(channelName); // Deserialize the string to a TradeResponse-entity var trade = Helper.ToEntity <TradeResponse>(message); // Invoke an event to let the subscribers know we have received trade information OnTradeMessage?.Invoke(tradeMarketInfo.Exchange, tradeMarketInfo.PrimaryCurrency, tradeMarketInfo.SecondaryCurrency, trade.TradeData.Trade); break; // Other cases for each MessageType... } }