sammchardy / python-binance

Binance Exchange API python implementation for automated trading
https://python-binance.readthedocs.io/en/latest/
MIT License
6.01k stars 2.2k forks source link

#auto-cancel-all-open-orders-trade #1152

Open tobeyond opened 2 years ago

tobeyond commented 2 years ago

Is the https://binance-docs.github.io/apidocs/futures/en/#auto-cancel-all-open-orders-trade method implemented in this wrapper? I'm not able to find the right fonction for it. futures_cancel_orders calls #cancel-multiple-orders-trade and it's not what I need. I want to implement thecountdownTimeover and over so if my bot stops, it kills all open orders.

varfigstar commented 2 years ago

See Client.futures_cancel_all_open_orders

silviumatei commented 1 year ago

Hello, is this method Client.futures_cancel_all_open_orders implemented for USD-M or only for Coin-M futures? When trying to use it with USD-M futures, I get a binance.exceptions.BinanceAPIException: APIError(code=-1121): Invalid symbol. for "ETHBUSD". So wondering what's the problem. Thanks!

fdeh75 commented 1 year ago

You can extend the Client class like this:

class MyBinanceClient(Client):
    """Extended python-binance `Client`: added countdown_cancel_all method"""
    def countdown_cancel_all(self, symbol: str, countdownTime: int, recvWindow: int = 5000):
        """Auto-Cancel All Open Orders
        https://binance-docs.github.io/apidocs/futures/en/#auto-cancel-all-open-orders-trade

        :param symbol: Name of symbol pair e.g. BNBBTC.
        :type symbol: str
        :param countdownTime: countdown time, 1000 for 1 second. 0 to cancel the timer
        :type countdownTime: int
        :param recvWindow: Optional; the number of milliseconds after timestamp the request is valid for (default is 5000)
        :type recvWindow: int

        :returns API response:

        .. code-block:: python
            {
                "symbol": "BTCUSDT",
                "countdownTime": "100000"
            }
        """
        return self._request_futures_api('post', 'countdownCancelAll', True,
                                         data=dict(symbol=symbol, countdownTime=countdownTime, recvWindow=recvWindow))