You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用Binance Connector Python API撤销订单时返回“Unknown order sent”问题

Binance测试网撤销订单返回-2011错误排查

背景

我使用Python的Binance Connector API在Binance测试网开发交易机器人。

遇到的问题

发送BTCUSDT订单撤销请求时,返回错误码-2011,提示“未知订单”。

相关日志

'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}

撤销订单代码

def cancel_order(self, id: int) -> None:
    self.currently_cancelling_order = True
    self.binance_api_client.cancel_order(
        symbol=self.TRADING_SYMBOL,
        orderId=id,
    )

我的排查

已确认订单ID正确(日志可验证),参考了官方撤销订单文档,猜测可能订单在操作过程中已成交,但不确定具体原因。


可能的原因及解决方法

  1. 订单状态已变更:虽然下单日志显示订单状态为NEW,但从下单(22:00:08)到发起撤销(22:00:11)的3秒内,订单可能已成交或因其他原因被系统撤销。建议在发起撤销前,先调用查询订单接口确认当前状态,仅对NEW或PARTIALLY_FILLED状态的订单执行撤销操作。

  2. API环境不匹配:确认客户端是否正确连接测试网。如果误使用了实网的API密钥和端点,会导致无法找到测试网的订单。检查客户端初始化配置,确保启用测试网模式。

  3. 请求方式不一致:日志显示实际发送的是WebSocket撤销请求,但代码中使用的是REST客户端的cancel_order方法。要确保代码逻辑与实际请求方式一致,WebSocket撤销需严格校验参数(如timestamp时间差、签名正确性),REST请求则要确认客户端配置无误。

  4. 订单ID归属错误:测试网订单ID是账户独立的,确认该orderId确实属于当前API密钥对应的测试账户,避免混用其他测试账户的订单ID。


内容的提问来源于stack exchange,提问作者David

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.09 05:51:03