JKorf / Bybit.Net

A C# .netstandard client library for the Bybit REST and Websocket V5 API focusing on clear usage and models
https://jkorf.github.io/Bybit.Net/
90 stars 64 forks source link

Deserialize JsonReaderException in SetLeverageAsync #107

Closed danielhw2 closed 1 year ago

danielhw2 commented 1 year ago

Hello...

I'm trying to set the Leverage on Bybit but I'm getting an error.

Bybit.Net ver 1.4.0 CryptoExchange.Net ver 5.3.1

The code:

var resultado = ClienteRest.InverseFuturesApi.Account.SetLeverageAsync("BTCUSDH23", 5, 5, 10000, CancellationToken.None).Result;

The exeption:

Deserialize JsonReaderException: Unexpected character encountered while parsing value: {. Path 'result', line 1, position 62., Path: result, LineNumber: 1, LinePosition: 62

The Log:

| Error | Bybit | [140] Deserialize JsonReaderException: Unexpected character encountered while parsing value: {. Path 'result', line 1, position 62., Path: result, LineNumber: 1, LinePosition: 62, data: [Data only available in Trace LogLevel]

kulikov-dev commented 1 year ago

@JKorf I'm not sure where it should be fixed: here or in CryptoExchange lib. The main problem is that we used int to return: public async Task<WebCallResult<int?>> SetLeverageAsync which is correct according to the API docs. However, if the exchange returns error, like: ;ret_msg&quot;: &quot;leverage not modified we got here deserialization error: "[11] Deserialize JsonReaderException: Error reading integer. Unexpected token: StartObject. Path 'result', line 1, position 62. Path: result, "

We still can get the initial exchange info using Trace flag, however it's not obvious and correct. I believe it should be solved somehow in the CryptoExchange library. What do you think about it?

JKorf commented 1 year ago

Although I'm not sure what the cause of the server error was, you should be able to get the error info correctly in the response model with the latest version

danielhw2 commented 1 year ago

All good. Thanks!!