{"record":{"id":"819fddba16549357","repo":"nautechsystems/nautilus_trader","slug":"cancel-order-failed","errorCode":null,"errorMessage":"cancel order failed","messagePattern":"cancel order failed","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/adapters/okx/src/execution.rs","lineNumber":993,"sourceCode":"                .cancel_order(\n                    command.trader_id,\n                    command.strategy_id,\n                    command.instrument_id,\n                    Some(command.client_order_id),\n                    command.venue_order_id,\n                )\n                .await;\n\n            if let Err(e) = result {\n                emit_cancel_failure(\n                    classify_okx_ws_failure(&e),\n                    None,\n                    command.client_order_id,\n                    command.instrument_id,\n                    command.strategy_id,\n                    command.venue_order_id,\n                );\n                return Err(anyhow::Error::new(e).context(\"cancel order failed\"));\n            }\n\n            Ok(())\n        });\n    }\n\n    fn cancel_order_http(&self, cmd: &CancelOrder) {\n        self.ensure_order_identity(cmd.client_order_id, cmd.strategy_id, cmd.instrument_id);\n\n        let http_client = self.http_client.clone();\n        let command = cmd.clone();\n        let emitter = self.emitter.clone();\n        let clock = self.clock;\n\n        self.spawn_task(\"cancel_order_http\", async move {\n            let result = http_client\n                .cancel_order(\n                    command.instrument_id,","sourceCodeStart":975,"sourceCodeEnd":1011,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/okx/src/execution.rs#L975-L1011","documentation":"Canceling a regular order over the OKX private WebSocket failed. ws_private.cancel_order returned an error, the adapter emitted an order cancel failure event (without an emitter event payload), and the task logs 'cancel order failed' with the underlying cause. Commonly a transport-level WS failure or OKX rejecting the cancel command.","triggerScenarios":"cancel_order routed to RegularWs; ws_private.cancel_order returned Err: WebSocket disconnected/reconnecting, request timeout awaiting OKX ack, or the client_order_id/venue_order_id no longer matches an open order (already filled or canceled).","commonSituations":"Canceling an order that was already filled or canceled; WS private connection dropped mid-session; canceling an order submitted in a prior process where no venue_order_id binding exists; OKX rejection codes returned on the WS channel.","solutions":["Read the chained cause for the OKX WS error; if the order no longer exists (already filled/canceled), treat the cancel as moot and let reconciliation update order state.","Check ws_private connection health; ensure the adapter was connected and authenticated (valid credentials, correct live/demo flag) before issuing cancels.","Retry the cancel via HTTP fallback if WS keeps failing, or use cancel_all_orders for bulk cleanup.","Ensure the cancel targets a live order: verify via the cache/reconciliation that the order is open and the venue_order_id binding is present."],"exampleFix":"// before: canceling without checking order state\ntrader.cancel_order(client_order_id);\n// after: only cancel open orders\nif let Some(order) = cache.order(&client_order_id) {\n    if !order.is_closed() {\n        trader.cancel_order(client_order_id);\n    }\n}","handlingStrategy":"try-catch","validationCode":"// Only cancel orders that are still open\nlet open = cache.order(&client_order_id).map(|o| !o.is_closed()).unwrap_or(false);\nif !open { return; }","typeGuard":null,"tryCatchPattern":"// Handle cancel failure without treating it as fatal\nif let Err(e) = trader.cancel_order(client_order_id) {\n    log::warn!(\"cancel failed: {e:?}\");\n    // rely on reconciliation to confirm final order state\n}","preventionTips":["Check order.is_closed() in the cache before canceling.","Run reconciliation after restarts so venue bindings exist for cancels.","Watch WS private connection status before issuing cancels.","Use HTTP cancel fallback when WS is unstable."],"tags":["okx","websocket","order-cancel","trading","network"],"backgroundTag":"network-request-failed","analyzedSha":"18893faf8b356be3320add8de2f861b0b647cf06","analyzedAt":"2026-09-08T20:49:34.690Z","contentChangedAt":"2026-09-08T20:49:34.690Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}