glitch100 / BinanceDotNet

Official C# Wrapper for the Binance exchange API, with REST and WebSocket endpoints
https://www.nuget.org/packages/BinanceDotNet/
MIT License
161 stars 138 forks source link

ConnectToIndividualSymbolTickerWebSocket !ticker@arr endpoint #154

Open Danford opened 5 years ago

Danford commented 5 years ago

Issue Overview

/// <summary>
/// Connect to the All Market Symbol Ticker WebSocket
/// </summary>
/// <param name="messageEventHandler"></param>
/// <returns></returns>
public Guid ConnectToIndividualSymbolTickerWebSocket(BinanceWebSocketMessageHandler<BinanceAggregateTradeData> messageEventHandler)

Connecting to this endpoint produces an error with the message:

Cannot deserialize the current JSON array (e.g. [1,2,3]) into type 'BinanceExchange.API.Models.WebSocket.BinanceAggregateTradeData' because the type requires a JSON object (e.g. {"name":"value"}) to deserialize correctly. To fix this error either change the JSON to a JSON object (e.g. {"name":"value"}) or change the deserialized type to an array or a type that implements a collection interface (e.g. ICollection, IList) like List\ that can be deserialized from a JSON array. JsonArrayAttribute can also be added to the type to force it to deserialize from a JSON array. Path '', line 1, position 1.

StackTrace:

at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.EnsureArrayContract(JsonReader reader, Type objectType, JsonContract contract) at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateList(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, Object existingValue, String id) at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent) at Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType) at Newtonsoft.Json.JsonConvert.DeserializeObject(String value, Type type, JsonSerializerSettings settings) at Newtonsoft.Json.JsonConvert.DeserializeObject[T](String value, JsonSerializerSettings settings) at BinanceExchange.API.Websockets.AbstractBinanceWebSocketClient.<>c__DisplayClass22_0`1.\b__1(Object sender, MessageEventArgs e) in C:\Users\joshu\Documents\Programming\Repo\BinanceDotNet\BinanceExchange.API\Websockets\AbstractBinanceWebSocketClient.cs:line 250 at WebSocketSharp.WebSocket.messagec(MessageEventArgs e)

line 250 AbstractBinanceWebSocketClient.cs var data = JsonConvert.DeserializeObject<T>(e.Data);

where T = BinanceWebSocketMessageHandler\

Package Version: 4.10

Repro Steps

            socket = new InstanceBinanceWebSocketClient(client);
            socket.ConnectToIndividualSymbolTickerWebSocket(a =>
            {
                System.Console.WriteLine($"{JsonConvert.SerializeObject(a, Formatting.Indented)}");
            });

Other Information

It would appear to me that the correct function declaration should be: public Guid ConnectToIndividualSymbolTickerWebSocket(BinanceWebSocketMessageHandler\<List\<BinanceTradeData>> messageEventHandler) but this causes other issues with the type constrant where T : IWebSocketResponse in AbstractBinanceWebSocketClient::CreateBinanceWebSocket.

I'm happy to assist with fixing this issue if you have any advice on an acceptable resolution.

glitch100 commented 5 years ago

Could you provide the JSON payload that it tries to Deserialize? We can then work on a decent solution 👍 @Danford