-2

I'm working with python-binance. In my code, I place a futures market order, using this code:

order = self.client.futures_create_order(
                symbol=coin_pare,
                type='MARKET',
                side=route,
                quantity=value * self.main_leverage,

            )

Then, when I want to close this order, I decide to use cancel_order in this library, using this code:

self.client.cancel_order(symbol=pare, orderId=order_id, origClientOrderId=client_order_id)

And I get an error: APIError(code=-2011): Unknown order sent. Is there another way how to cancel certain order?

Zeroch1
  • 1
  • 1
  • 1

2 Answers2

0

timestamp is mandatory in parameters for cancel orders mentioned in https://binance-docs.github.io/apidocs/futures/en/#query-order-user_data you should edit like this:

(self.client.cancel_order(symbol=pare, orderId=order_id, origClientOrderId=client_order_id, timestamp=true)
Jeremy Caney
  • 7,102
  • 69
  • 48
  • 77
0

You just need to remove spaces and encode the string. Do this:

from urllib.parse import quote
from json import dumps
    
    order_id_str = dumps(order_id).replace(" ", "")
    order_id_str = quote(order_id_str)
    self.client.cancel_order(symbol=pare, orderIdList=order_id_str)