wisespace-io / binance-rs

Rust Library for the Binance API
Other
665 stars 297 forks source link

[BUG] Exchange info deserializer not working #44

Closed clementpl closed 4 years ago

clementpl commented 4 years ago

Hello,

First, thank you for your work. I'm moving a project from nodejs which is using ccxt to rust and I was really happy to found this library to going faster. But I found something weird when using the General api. It looks like there is a problem while deserializing exchange information

let general: General = Binance::new(None, None);
let info = match general.exchange_info() {
                Ok(info) => info,
                Err(e) => panic!("Cannot get exchange info [{:?}]", e),
};

I'm getting this error

Error(Json(Error("missing field `limit`", line: 1, column: 1399)), State { next_error: None, backtrace: InternalBacktrace { backtrace: None } })

I look at the 1399 column of the exchange info result Which after "maxNumOrders":200 {"filterType":"MAX_NUM_ORDERS","maxNumOrders":200}

And it looks like there is no limit field but in your model in the enum filter it is define with

    #[serde(rename = "MAX_NUM_ORDERS")]
    #[serde(rename_all = "camelCase")]
    MaxNumOrders { limit: u16 },

I replace in my local build with

    MaxNumOrders { },

And it works.

If you want I can manage to do a PR. Or if you can handle the correction. Thank you.

wisespace-io commented 4 years ago

@clementpl Acccording to the documentation it should have a "limit", so it may be optional now, or it always was but not stated in the docs.

https://github.com/binance-exchange/binance-official-api-docs/blob/master/rest-api.md#filters

Anyway, added an Option, so it will not break again.

MaxNumOrders { limit: Option<u16> },

Thank you for reporting.

clementpl commented 4 years ago

Perfect thank you

naviialto commented 3 years ago

I found the error "missing field minNotional" in FuturesGeneral::exchange_info().

let general: FuturesGeneral= Binance::new(None, None);
let info = match general.exchange_info() {
                Ok(info) => info,
                Err(e) => panic!("Cannot get exchange info [{:?}]", e),
};

answer json

{"notional":"1","filterType":"MIN_NOTIONAL"}

After modifying the source for the above reasons, it runs success.

    MinNotional {
        min_notional: Option<String>,
        apply_to_market: Option<bool>,
        avg_price_mins: Option<f64>,
    }
wisespace-io commented 3 years ago

@naviialto Thank you for reporting, I will fix it!