{"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":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/adapters/binance/src/futures/http/client.rs","lineNumber":2514,"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":2496,"sourceCodeEnd":2532,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/binance/src/futures/http/client.rs#L2496-L2532","documentation":"The Binance Futures algo-order cancel endpoint returns a response with a code and msg; success is code == 200. Any other code (exchange rejects the cancel) causes this error with the exchange's code and message.","triggerScenarios":"Calling cancel_algo_order for a conditional/algo order that does not exist (already filled or canceled), belongs to a different symbol, or when the account lacks permission / the algo ID is wrong.","commonSituations":"Cancelling a stop that already triggered and executed; stale algo order IDs kept in local state; using the wrong algo ID type (strategy vs order ID).","solutions":["Check the returned msg for the exact exchange reason (e.g. 'Unknown order sent') and treat unknown-order as already-closed","Verify the algo order is still active via an algo order status query before canceling","Ensure the symbol and algo ID match the original algo order","Refresh local algo-order state via reconciliation if IDs are stale"],"exampleFix":"// before\nclient.cancel_algo_order(symbol, algo_id)?; // hard fail on unknown order\n// after\nmatch client.cancel_algo_order(symbol, algo_id) {\n    Ok(_) => {},\n    Err(e) if e.to_string().contains(\"Unknown order\") => log::info!(\"algo order already gone\"),\n    Err(e) => return Err(e),\n}","handlingStrategy":"try-catch","validationCode":"let active = client.query_algo_order_status(symbol, algo_id)?;\nif !active { return Ok(()); } // nothing to cancel","typeGuard":null,"tryCatchPattern":"match client.cancel_algo_order(symbol, algo_id) { Err(e) if e.to_string().contains(\"Unknown order\") => Ok(()), Err(e) => Err(e), _ => Ok(()) }","preventionTips":["Sync algo order state via periodic reconciliation","Treat unknown-order cancel errors as idempotent success","Confirm symbol and algo IDs before cancelling"],"tags":["rust","binance","algo-order","cancel","exchange-rejection"],"backgroundTag":"api-error-response","analyzedSha":"18893faf8b356be3320add8de2f861b0b647cf06","analyzedAt":"2026-09-08T20:49:34.690Z","contentChangedAt":"2026-09-08T20:49:34.690Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}