wisespace-io / binance-rs

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

handle binance's errors with more precision #20

Closed dizda closed 5 years ago

dizda commented 5 years ago

This allows to be more specific when managing errors and take action accordingly.

use binance::errors::ErrorKind as BinanceLibErrorKind;

[...]

Err(err) => {
    println!("Can't put an order!");

    match err.0 {
        BinanceLibErrorKind::BinanceError(code, msg, response) => match code {
            -1013_i16 => println!("Filter failure: LOT_SIZE!"),
            -2010_i16 => println!("Funds insufficient! {}", msg),
            _ => println!("Non-catched code {}: {}", code, msg),
        },
        BinanceLibErrorKind::Msg(msg) => {
            println!("Binancelib error msg: {}", msg)
        }
        _ => println!("Other errors: {}.", err.0),
    };
}
dizda commented 5 years ago

That might introduce a BC-Break though. Maybe better to bump a minor version.

wisespace-io commented 5 years ago

@dizda Thank you again, I updated the README with the example you provided.

dizda commented 5 years ago

Great. Thank you!