{"record":{"id":"622c7e1ba9f57bed","repo":"nautechsystems/nautilus_trader","slug":"cancel-order-failed-e","errorCode":null,"errorMessage":"Cancel order failed: {e}","messagePattern":"Cancel order failed: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/adapters/deribit/src/execution.rs","lineNumber":973,"sourceCode":"\n        log::debug!(\"Canceling order: order_id={order_id}, client_order_id={client_order_id}\");\n\n        // Spawn async task to send cancel via WebSocket\n        self.spawn_task(\"cancel_order\", async move {\n            if let Err(e) = ws_client\n                .cancel_order(\n                    &order_id,\n                    client_order_id,\n                    trader_id,\n                    strategy_id,\n                    instrument_id,\n                )\n                .await\n            {\n                log::error!(\n                    \"Cancel order failed: order_id={order_id}, client_order_id={client_order_id}, error={e}\"\n                );\n                anyhow::bail!(\"Cancel order failed: {e}\");\n            }\n            Ok(())\n        });\n\n        Ok(())\n    }\n\n    fn cancel_all_orders(&self, cmd: CancelAllOrders) -> anyhow::Result<()> {\n        let instrument_id = cmd.instrument_id;\n\n        // Without a side filter, use efficient bulk cancel via Deribit API\n        let Some(order_side) = cmd.order_side else {\n            log::debug!(\n                \"Cancelling all orders: instrument={instrument_id}, order_side=None (bulk)\"\n            );\n\n            let ws_client = self.ws_client.clone();\n            self.spawn_task(\"cancel_all_orders\", async move {","sourceCodeStart":955,"sourceCodeEnd":991,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/deribit/src/execution.rs#L955-L991","documentation":"The cancel_order command runs in a spawned task; if the ws_client cancel-order request to Deribit fails, the error is logged with order_id and client_order_id and re-raised as 'Cancel order failed: {e}'. Like modify_order, cancel_order returns Ok(()) immediately; the failure is observable only in the spawned task's error path.","triggerScenarios":"Calling cancel_order for an order_id/client_order_id unknown to Deribit, an already-filled or cancelled order, or when the request fails due to auth, rate limits, or a dropped WebSocket connection.","commonSituations":"Cancelling an order that was just filled (common race in fast markets); duplicate cancel attempts; stale order IDs after reconnect; WebSocket disconnection mid-request.","solutions":["Inspect the logged inner error for the venue rejection reason (e.g. unknown order vs connection failure)","Verify the order is still open before cancelling; treat 'already filled/cancelled' rejections as benign","Check WebSocket connectivity and re-authenticate if the session dropped","Retry the cancel once connectivity is restored, or use cancel_all_orders as a safety net"],"exampleFix":"// before\nif let Err(e) = ws_client.cancel_order(order_id, client_order_id).await {\n    anyhow::bail!(\"Cancel order failed: {e}\");\n}\n// after\nif let Err(e) = ws_client.cancel_order(order_id, client_order_id).await {\n    if !e.to_string().contains(\"not found\") && !e.to_string().contains(\"already\") {\n        anyhow::bail!(\"Cancel order failed: {e}\");\n    }\n    log::info!(\"order already inactive on venue: {order_id}\");\n}","handlingStrategy":"try-catch","validationCode":"// Before cancelling, confirm the order is still live\nif !open_orders.contains(&venue_order_id) {\n    log::info!(\"skip cancel: order not open\");\n    return Ok(());\n}","typeGuard":null,"tryCatchPattern":"match client.cancel_order(cmd).await {\n    Ok(()) => {}, // failure surfaces asynchronously in the spawned task\n    Err(e) => log::error!(\"cancel dispatch failed: {e}\"),\n}\n// on 'Cancel order failed' in task logs, treat already-filled/cancelled as benign","preventionTips":["Maintain accurate local open-order state to avoid cancelling dead orders","Deduplicate cancel requests for the same order_id","Monitor spawned-task logs for the venue rejection reason","Use cancel_all_orders as a periodic safety net during disconnects"],"tags":["order-management","websocket","deribit","async"],"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-14T05:17:10.506Z"}