in

Python – cancel all open orders

I’m using the python-binance API and trying to recreate the `DELETE api/v3/openOrders` endpoint. I originally tried this solution recommended on the python-binance GitHub page:

def cancel_orders(self, **params):
return self._delete(‘openOrders’, True, data=params)

But I was getting the following response: `APIError(code=-2011): Unknown order sent.`

So I tried replicating the request like this:

def cancel_open_orders(self, **params):
uri = self._create_api_uri(“openOrders”, True, self.PUBLIC_API_VERSION)
kwargs = self._get_request_kwargs(“delete”, True, force_params=False, data=params)
data = { arg[0]: arg[1] for arg in kwargs[“data”] }
print(uri)
print(data)
headers = {“X-MBX-APIKEY”: self.API_KEY}
results = requests.delete(uri, data=data, headers=headers)
print(results)

`uri` and `data` print as

https://api.binance.com/api/v3/openOrders

{‘symbol’: ‘BTCUSDT’, ‘timestamp’: ‘1625894171675’, ‘signature’: ‘567c2dda12a0b8e26f66130ee2cf0187d630e7c4e69949e5b1ee7305cb1008b9’}

Using this method, I get a simple `<Response [400]>` response.

How can I implement this in vanilla python?

What do you think?

10 Points
Upvote Downvote

Leave a Reply

Your email address will not be published. Required fields are marked *

GIPHY App Key not set. Please check settings

NEWTON FAIR LAUNCH NOW