binance-rs icon indicating copy to clipboard operation
binance-rs copied to clipboard

Unified approach for all future markets

Open dorak88783 opened this issue 3 years ago • 6 comments

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?

dorak88783 avatar Jul 18 '21 14:07 dorak88783

@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.

wisespace-io avatar Jul 19 '21 06:07 wisespace-io

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

seguidor777 avatar Aug 03 '21 03:08 seguidor777

@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.

wisespace-io avatar Aug 04 '21 08:08 wisespace-io

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

seguidor777 avatar Aug 04 '21 15:08 seguidor777

@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)
            },
        }
    }

francesco-gaglione avatar Dec 14 '21 15:12 francesco-gaglione