/// <summary>
        /// Handles object messages sent by bitmex.
        /// </summary>
        /// <param name="msg">The MSG.</param>
        /// <param name="streams">The streams.</param>
        /// <returns></returns>
        public static bool HandleObjectMessage(string msg, BitmexClientStreams streams)
        {
            var response = BitmexJsonSerializer.Deserialize <JObject>(msg);

            // ********************
            // ADD OBJECT HANDLERS BELOW
            // ********************

            return
                (TradeResponse.TryHandle(response, streams.TradesSubject) ||
                 TradeBinResponse.TryHandle(response, streams.TradeBinSubject) ||
                 BookResponse.TryHandle(response, streams.BookSubject) ||
                 QuoteResponse.TryHandle(response, streams.QuoteSubject) ||
                 LiquidationResponse.TryHandle(response, streams.LiquidationSubject) ||
                 PositionResponse.TryHandle(response, streams.PositionSubject) ||
                 MarginResponse.TryHandle(response, streams.MarginSubject) ||
                 OrderResponse.TryHandle(response, streams.OrderSubject) ||
                 WalletResponse.TryHandle(response, streams.WalletSubject) ||
                 InstrumentResponse.TryHandle(response, streams.InstrumentSubject) ||
                 ExecutionResponse.TryHandle(response, streams.ExecutionSubject) ||
                 FundingResponse.TryHandle(response, streams.FundingsSubject) ||


                 ErrorResponse.TryHandle(response, streams.ErrorSubject) ||
                 SubscribeResponse.TryHandle(response, streams.SubscribeSubject) ||
                 InfoResponse.TryHandle(response, streams.InfoSubject) ||
                 AuthenticationResponse.TryHandle(response, streams.AuthenticationSubject));
        }
Exemplo n.º 2
0
        private bool HandleObjectMessage(string msg)
        {
            var response = BitmexJsonSerializer.Deserialize <JObject>(msg);

            // ********************
            // ADD OBJECT HANDLERS BELOW
            // ********************

            return

                (TradeResponse.TryHandle(response, Streams.TradesSubject) ||
                 TradeBinResponse.TryHandle(response, Streams.TradeBinSubject) ||
                 BookResponse.TryHandle(response, Streams.BookSubject) ||
                 QuoteResponse.TryHandle(response, Streams.QuoteSubject) ||
                 LiquidationResponse.TryHandle(response, Streams.LiquidationSubject) ||
                 PositionResponse.TryHandle(response, Streams.PositionSubject) ||
                 OrderResponse.TryHandle(response, Streams.OrderSubject) ||
                 WalletResponse.TryHandle(response, Streams.WalletSubject) ||


                 ErrorResponse.TryHandle(response, Streams.ErrorSubject) ||
                 SubscribeResponse.TryHandle(response, Streams.SubscribeSubject) ||
                 InfoResponse.TryHandle(response, Streams.InfoSubject) ||
                 AuthenticationResponse.TryHandle(response, Streams.AuthenticationSubject));
        }
        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");
            }
        }
        public void String_Enum_CamelCase_Test()
        {
            var str = "{\"myEnum\":\"testValue\"}";

            var cls = BitmexJsonSerializer.Deserialize <MyClass>(str);

            cls.MyEnum.Should().Be(MyEnum.TestValue);
        }
Exemplo n.º 5
0
 internal static bool TryParse(JsonElement response, Action <WelcomeInfoResponse> action)
 {
     if (response.TryGetProperty("info", out _) && response.TryGetProperty("version", out _))
     {
         var welcomeInfoResponse = BitmexJsonSerializer.Deserialize <WelcomeInfoResponse>(response);
         action?.Invoke(welcomeInfoResponse);
         return(true);
     }
     return(false);
 }
Exemplo n.º 6
0
 internal static bool TryParse(JsonElement response, Action <UnsubscribeResponse> action)
 {
     if (response.TryGetProperty("unsubscribe", out _))
     {
         var unsubscribeResponse = BitmexJsonSerializer.Deserialize <UnsubscribeResponse>(response);
         action?.Invoke(unsubscribeResponse);
         return(true);
     }
     return(false);
 }
Exemplo n.º 7
0
        internal static bool TryHandle(string response, ISubject <InfoResponse> subject)
        {
            if (!BitmexJsonSerializer.ContainsProperty(response, "info"))
            {
                return(false);
            }

            var parsed = BitmexJsonSerializer.Deserialize <InfoResponse>(response);

            subject.OnNext(parsed);
            return(true);
        }
 internal static bool TryHandle(JsonElement response, Action <CancelAllAfterResponse> action)
 {
     if (response.TryGetProperty("request", out var request) &&
         request.TryGetProperty("op", out var op) &&
         op.GetString() == "cancelAllAfter")
     {
         var cancelAllAfterResponse = BitmexJsonSerializer.Deserialize <CancelAllAfterResponse>(response);
         action?.Invoke(cancelAllAfterResponse);
         return(true);
     }
     return(false);
 }
Exemplo n.º 9
0
        internal static bool TryHandle(string response, ISubject <AuthenticationResponse> subject)
        {
            if (!BitmexJsonSerializer.ContainsValue(response, "authKey"))
            {
                return(false);
            }

            var parsed = BitmexJsonSerializer.Deserialize <AuthenticationResponse>(response);

            subject.OnNext(parsed);
            return(true);
        }
Exemplo n.º 10
0
 public static bool TryHandle(JsonElement response, Action <TableResponse <T> > action, SubscriptionType subscriptionType)
 {
     if (response.TryGetProperty("table", out var table) &&
         Enum.TryParse(table.GetString(), true, result: out SubscriptionType subscription) &&
         subscription == subscriptionType)
     {
         var tableResponse = BitmexJsonSerializer.Deserialize <TableResponse <T> >(response);
         action?.Invoke(tableResponse);
         return(true);
     }
     return(false);
 }
Exemplo n.º 11
0
 internal static bool TryParse(JsonElement response, Action <AuthenticationResponse> action)
 {
     if (response.TryGetProperty("request", out var request) &&
         request.TryGetProperty("op", out var op) &&
         op.GetString() == "authKeyExpires")
     {
         var authenticationResponse = BitmexJsonSerializer.Deserialize <AuthenticationResponse>(response);
         action?.Invoke(authenticationResponse);
         return(true);
     }
     return(false);
 }
        internal static bool TryHandle(string response, ISubject <BookResponse> subject)
        {
            if (!BitmexJsonSerializer.ContainsValue(response, "orderBookL2"))
            {
                return(false);
            }

            var parsed = BitmexJsonSerializer.Deserialize <BookResponse>(response);

            subject.OnNext(parsed);

            return(true);
        }
Exemplo n.º 13
0
        internal static bool TryHandle(string response, ISubject <TradeBinResponse> subject)
        {
            if (!BitmexJsonSerializer.ContainsRaw(response, "tradeBin"))
            {
                return(false);
            }

            var parsed = BitmexJsonSerializer.Deserialize <TradeBinResponse>(response);

            parsed.Size = parsed.Table?.Replace("tradeBin", string.Empty).Trim();
            subject.OnNext(parsed);

            return(true);
        }