{"record":{"id":"9ccea5ad0104e119","repo":"nautechsystems/nautilus_trader","slug":"cancel-algo-order-failed-code-msg","errorCode":null,"errorMessage":"Cancel algo order failed: code={}, msg={}","messagePattern":"Cancel algo order failed: code=(.+?), msg=(.+?)","errorType":"http","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/adapters/binance/src/futures/http/client.rs","lineNumber":2420,"sourceCode":"    ///\n    /// # Errors\n    ///\n    /// Returns an error if the request fails.\n    pub async fn cancel_algo_order(&self, client_order_id: ClientOrderId) -> anyhow::Result<()> {\n        let params = BinanceAlgoOrderQueryParams {\n            algo_id: None,\n            client_algo_id: Some(encode_broker_id(\n                &client_order_id,\n                BINANCE_NAUTILUS_FUTURES_BROKER_ID,\n            )),\n            recv_window: None,\n        };\n\n        let response = self.inner.cancel_algo_order(&params).await?;\n        if response.code.parse::<i32>().unwrap_or(0) == 200 {\n            Ok(())\n        } else {\n            anyhow::bail!(\n                \"Cancel algo order failed: code={}, msg={}\",\n                response.code,\n                response.msg\n            )\n        }\n    }\n\n    /// Cancels all open orders for a symbol.\n    ///\n    /// # Errors\n    ///\n    /// Returns an error if the request fails.\n    pub async fn cancel_all_orders(\n        &self,\n        instrument_id: InstrumentId,\n    ) -> anyhow::Result<Vec<VenueOrderId>> {\n        let symbol = format_binance_symbol(&instrument_id);\n","sourceCodeStart":2402,"sourceCodeEnd":2438,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/a4b06ed870971b5671d12754ea138a3ab99b1dec/crates/adapters/binance/src/futures/http/client.rs#L2402-L2438","documentation":"Thrown by BinanceFuturesHttpClient::cancel_algo_order when the Binance Algo (conditional order) service returns a response whose code field is not 200. The HTTP layer succeeded (signature, connectivity, rate limits are fine); the algo endpoint itself reported a business failure, and the message embeds the venue's code and msg verbatim. NautilusTrader treats any non-200 code as a failed cancel rather than surfacing a typed per-code error.","triggerScenarios":"Canceling via cancel_algo_order(client_order_id) where the client_algo_id (broker-prefixed via encode_broker_id with BINANCE_NAUTILUS_FUTURES_BROKER_ID) does not match any open algo order: order already triggered, expired, or already canceled; submitting the algo order on a different API key/account than the one used to cancel; the order was a regular (non-algo) order submitted through submit_order, not the algo endpoint.","commonSituations":"Strategy restarts that attempt to clean up algo orders which already fired during downtime; testnet keys paired against production endpoints (or vice versa) so the algo ID is unknown to that environment; racing another cancel path (websocket + HTTP) so the second cancel sees an already-canceled order.","solutions":["Match the exact msg string for the common benign case (order already terminated/triggered) and treat it as success instead of an error","Confirm the client_order_id is the same one used when the algo order was submitted through this same client (it gets broker-prefixed before sending)","Verify the API key, permissions, and environment (testnet vs prod) are identical to those used at submission time","Re-query open algo orders before canceling to only cancel IDs that are still live"],"exampleFix":"// before\nclient.cancel_algo_order(client_order_id).await?;\n\n// after\nif let Err(e) = client.cancel_algo_order(client_order_id).await {\n    let msg = format!(\"{e}\");\n    if msg.contains(\"already\") || msg.contains(\"does not exist\") {\n        log::info!(\"algo order already gone: {e}\");\n    } else {\n        return Err(e);\n    }\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"// before canceling, only target still-open algo orders\nfor report in client.request_open_algo_orders().await? {\n    if report.client_order_id == target {\n        client.cancel_algo_order(target).await?;\n    }\n}","preventionTips":["Treat 'already terminated / does not exist' style msgs as success in cleanup flows","Submit and cancel algo orders with the same API key and environment","Re-query open algo orders before canceling after a restart gap"],"tags":["binance","futures","algo-order","order-cancel","rust","nautilustrader"],"backgroundTag":"order-cancel-rejected","analyzedSha":"a4b06ed870971b5671d12754ea138a3ab99b1dec","analyzedAt":"2026-08-16T22:54:50.089Z","schemaVersion":2},"datasetVersion":"2026-08-16T23:17:17.608Z"}