glitch100 / BinanceDotNet

Official C# Wrapper for the Binance exchange API, with REST and WebSocket endpoints

Home Page:https://www.nuget.org/packages/BinanceDotNet/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Reading from individual symbol ticker stream fails

filippopovic opened this issue · comments

Issue Overview

Reading Individual symbol ticker stream fails with exception message

Newtonsoft.Json.JsonSerializationException: 'Error converting value "3682.92000000" to type 'System.Int64'. Path 'a', line 1, position 213.'

Package Version: 4.7.0

Repro Steps

Here is the code to reproduce error.

        var client = new BinanceClient(new ClientConfiguration()
        {
            ApiKey = apiKey,
            SecretKey = secretKey,
            Logger = exampleProgramLogger,
        });

       var socket = new InstanceBinanceWebSocketClient(client);
        var sId = socket.ConnectToIndividualSymbolTickerWebSocket("BTCUSDT", b =>
        {
            System.Console.Clear();
            System.Console.WriteLine($"{JsonConvert.SerializeObject(b, Formatting.Indented)}");
            System.Console.SetWindowPosition(0, 0);
        });
##### Other Information
Line of code where exception ocurs.
AbstractBinanceWebSocketClient.cs, line 250
`var data = JsonConvert.DeserializeObject<T>(e.Data);`
it belongs to method
`private Guid CreateBinanceWebSocket<T>(Uri endpoint, BinanceWebSocketMessageHandler<T> messageEventHandler) where T : IWebSocketResponse`

Found out that T is BinanceAggregateTradeData using debugger. Seems like we should have another Models/WebSocket class that will represent ticker stream response, because AggregateTradeData does not conform to json response. Or some other class should be used for T. Can't find how it got this class anyway.

Do you want to put up a PR for this? It looks like one of the types is off

it is trying to deserialize to an object of type BinanceAggregateTradeData , consequently AggregateTradeId fails because the return type is really best asking price. I'm a newbie hoping to contribute a bit. i changed the endpoint to {symbol.ToLower()}@aggTrade from {symbol.ToLower()}@ticker and all was well but method name suggests desired output is the ticker not aggregated which i have not yet seen an object for it. new model or endpoint fix ?