I'm using the binance connector API with python https://binance-connector.readthedocs.io/en/latest/ with the testnet (https://testnet.binance.vision/) to build a trading bot.
The problem that I have is that I'm sending a request to cancel an order on a certain symbol and I get back 'unknown order received'.
This is the log:
'rateLimits': [ { 'count': 17,
'interval': 'MINUTE',
'intervalNum': 1,
'limit': 6000,
'rateLimitType': 'REQUEST_WEIGHT'}],
'result': { 'clientOrderId': 'ECryC5RymE2cD4u50P11HI',
'cummulativeQuoteQty': '0.00000000',
'executedQty': '0.00000000',
'icebergQty': '0.00000000',
'isWorking': True,
'orderId': 12264945,
'orderListId': -1,
'origQty': '0.00054600',
'origQuoteOrderQty': '0.00000000',
'price': '27449.33000000',
'selfTradePreventionMode': 'NONE',
'side': 'BUY',
'status': 'NEW',
'stopPrice': '0.00000000',
'symbol': 'BTCUSDT',
'time': 1696284008962,
'timeInForce': 'GTC',
'type': 'LIMIT',
'updateTime': 1696284008962,
'workingTime': 1696284008962},
'status': 200}
----------------------------------------------------------------------------------------------------
2023-10-02 22:00:11.073 UTC DEBUG binance.websocket.websocket_client: Sending message to Binance WebSocket Server: {"id": "48b42ef9-6e14-467c-b35c-7f6e52de514c", "method": "depth", "params": {"symbol": "BTCUSDT", "limit": 1}}
----------------------------------------------------------------------------------------------------
{ 'id': '48b42ef9-6e14-467c-b35c-7f6e52de514c',
'rateLimits': [ { 'count': 19,
'interval': 'MINUTE',
'intervalNum': 1,
'limit': 6000,
'rateLimitType': 'REQUEST_WEIGHT'}],
'result': { 'asks': [['27447.71000000', '0.02714400']],
'bids': [['27447.70000000', '0.03461200']],
'lastUpdateId': 20964071},
'status': 200}
----------------------------------------------------------------------------------------------------
2023-10-02 22:00:11.307 UTC DEBUG binance.websocket.websocket_client: Sending message to Binance WebSocket Server: {"id": "f6ab36b1-3618-4061-bedd-d1046a3ee52a", "method": "order.cancel", "params": {"apiKey": "5aBdL8xhcEukeAqemVb5H0JSTXpAPYrX07BcHGw0WAjvJS4kClsLvT7rGkgyYsqA", "orderId": 12264945, "symbol": "BTCUSDT", "timestamp": 1696284011307, "signature": "cabf41556cd22cf6af425729a9e77a042d3a77958c5d8118922bc67f1546957c"}}
----------------------------------------------------------------------------------------------------
{ 'error': {'code': -2011, 'msg': 'Unknown order sent.'},
'id': 'f6ab36b1-3618-4061-bedd-d1046a3ee52a',
'rateLimits': [ { 'count': 20,
'interval': 'MINUTE',
'intervalNum': 1,
'limit': 6000,
'rateLimitType': 'REQUEST_WEIGHT'}],
'status': 400}
This is the code for the cancel order:
def cancel_order(self, id: int) -> None:
self.currently_cancelling_order = True
self.binance_api_client.cancel_order(
symbol=self.TRADING_SYMBOL,
orderId=id,
)
The id for the order I'm trying to cancel is always correct, no matter what, you can check this in the log file as well.
This is the documentation for the request to cancel: https://binance-connector.readthedocs.io/en/latest/binance.spot.trade.html?order#binance.spot.trade.cancel_order.
I think it's possible that my order might have gotten filled somewhere during the process and when I'm trying to cancel it, I can't cancel it anymore, so I get this answer back.
What am I doing wrong?
I was getting this error because I was trying to cancel an order that has gotten filled.