wisespace-io / binance-rs

Rust Library for the Binance API
Other
636 stars 287 forks source link

Unified approach for all future markets #125

Open dorak88783 opened 2 years ago

dorak88783 commented 2 years ago

The current implementation of futures endpoints is geared mainly to the USD-M futures (link): e.g. https://github.com/wisespace-io/binance-rs/blob/master/src/config.rs#L18 and https://github.com/wisespace-io/binance-rs/blob/master/src/api.rs#L129 all have fapi hardcoded, but there is also dapi for the COIN-M futures (link) and vapi for the Vanilla options (link). I guess this is historical, since the USD-M futures first were the only type offered and the others are added laters (leading to confusing urls "futures" and "delivery" for USD-M and COIN-M respectively).

To properly support those futures types I see two options:

  1. add new methods for all other future types. This is what python-binance did: you can see at https://python-binance.readthedocs.io/en/latest/binance.html there's methods like futures_account and futures_coin_account_balance: each of the *_coin_* methods is a duplicate to serve the COIN-M futures.
  2. create new methods that require an extra future market type (e.g. COINM, USDM, VANILLA).

My preference is the 2nd method as it makes the API much simpler and code can be re-used, but this would be a major breaking change to the current API. What do you think?

wisespace-io commented 2 years ago

@dorak88783 I also prefer the second option. I don't think it would be a major problem as I guess we have few users of the Futures api in the current state. Binance team probably did not have choice and duplicated the methods.

seguidor777 commented 2 years ago

Escuse me, does this client support trading with futures? And is there any documentation?

wisespace-io commented 2 years ago

@seguidor777 We do not have a documentation, you can check the Examples folder to Binance Futures Endpoint and Websockets examples with the current supported features. You can also check the https://github.com/wisespace-io/binance-rs/blob/master/src/futures/account.rs .. we provide some trading options, not documented yet.

Be aware that Futures Support is currently under development with some upcoming breaking changes.

seguidor777 commented 2 years ago

Hi @wisespace-io, thanks for sharing that. I already have seen the examples and didn't find anything about the limit buy orders creation. However looking into the code of account.rs I see that it's already supported and it seems to have all the options that I need. I'll just try it, thanks for pointing me to the right direction

francesco-gaglione commented 2 years ago

@seguidor777 I implemented a custom order type into the futures api, with my older nickname. Anyway, this is an example for limit orders:


let binance: Binance::new(
                    Option::from(chiave.clone()),
                    Option::from(chiave_privata.clone()),
                )

........

 pub fn open_long_limit(&self, symbol: String, quantity: f64, price: f64) -> Result<bool, Error> {
        let order: CustomOrderRequest = CustomOrderRequest{
            symbol: symbol.into(),
            side: OrderSide::Buy,
            position_side: None,
            order_type: OrderType::StopMarket,
            time_in_force: None,
            qty: Option::from(quantity),
            reduce_only: Option::from(false),
            price: None,
            stop_price: Some(price.into()),
            close_position: Some(false),
            activation_price: None,
            callback_rate: None,
            working_type: None,
            price_protect: None,
        };
        match self.binance.custom_order(order) {
            Ok(_answer) => {
                Ok(true)
            },
            Err(e) => {
                println!("Error: {:?}", e);
                Err(e)
            },
        }
    }