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?
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)
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)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.