private void HandleMessage(ResponseMessage message)
        {
            try
            {
                var messageSafe = (message.Text ?? string.Empty).Trim();

                // index 0 = MessageType
                // index 1 = ChannelId
                // index 2 = ChannelName
                // index 3 = Payload (nullable)
                var deserialized = BitmexJsonSerializer.Deserialize <List <object> >(messageSafe);
                if (deserialized.Count == 4 &&
                    Guid.TryParse(deserialized[1].ToString(), out Guid channelGuid) &&
                    _channels.TryGetValue(channelGuid, out BitmexWebsocketChannel channel))
                {
                    var payload = deserialized[3].ToString();
                    BitmexResponseHandler.HandleObjectMessage(payload, channel.Streams);
                    return;
                }
                Debug.WriteLine($"Unhandled response:  '{messageSafe}'");
            }
            catch (Exception e)
            {
                Debug.WriteLine("Exception while receiving message");
            }
        }
Exemplo n.º 2
0
        private void HandleMessage(ResponseMessage message)
        {
            try
            {
                bool handled;
                var  messageSafe = (message.Text ?? string.Empty).Trim();

                if (messageSafe.StartsWith("{"))
                {
                    handled = BitmexResponseHandler.HandleObjectMessage(messageSafe, Streams);
                    if (handled)
                    {
                        return;
                    }
                }

                handled = BitmexResponseHandler.HandleRawMessage(messageSafe, Streams);
                if (handled)
                {
                    return;
                }

                Log.Warn(L($"Unhandled response:  '{messageSafe}'"));
            }
            catch (Exception e)
            {
                Log.Error(e, L("Exception while receiving message"));
            }
        }