{"record":{"id":"c7a13dee0ab998a1","repo":"nautechsystems/nautilus_trader","slug":"cancel-all-orders-failed-e","errorCode":null,"errorMessage":"Cancel all orders failed: {e}","messagePattern":"Cancel all orders failed: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/adapters/deribit/src/execution.rs","lineNumber":994,"sourceCode":"        });\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 {\n                if let Err(e) = ws_client.cancel_all_orders(instrument_id, None).await {\n                    log::error!(\"Cancel all orders failed for instrument {instrument_id}: {e}\");\n                    anyhow::bail!(\"Cancel all orders failed: {e}\");\n                }\n                Ok(())\n            });\n\n            return Ok(());\n        };\n\n        // For specific side (Buy/Sell), filter from cache and cancel individually\n        // Deribit API doesn't support side filtering, so we implement it locally\n        log::debug!(\n            \"Cancelling orders by side: instrument={instrument_id}, order_side={order_side}\"\n        );\n\n        let orders_to_cancel: Vec<_> = {\n            let cache = self.core.cache();\n            let open_orders = cache.orders_open(None, Some(&instrument_id), None, None, None);\n\n            open_orders","sourceCodeStart":976,"sourceCodeEnd":1012,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/deribit/src/execution.rs#L976-L1012","documentation":"cancel_all_orders issues a bulk cancel for a given instrument via ws_client.cancel_all_orders inside a spawned task; any failure from Deribit is logged with the instrument_id and re-raised as 'Cancel all orders failed: {e}'. The public method returns Ok(()) immediately; the failure occurs asynchronously.","triggerScenarios":"Calling cancel_all_orders(instrument_id) when the Deribit bulk cancel-by-instrument request fails — instrument not recognized, no active session/auth, connection drop, or Deribit-side rejection.","commonSituations":"Flatten-all risk flows during volatility when the WebSocket is degraded; using an instrument_id not currently listed on Deribit; unauthenticated private session after reconnect.","solutions":["Check the logged inner error and instrument_id for the venue rejection reason","Verify the WebSocket connection and auth state before relying on bulk cancel for risk reduction","Confirm the instrument_id is a valid, currently listed Deribit instrument","Fall back to per-order cancels if bulk cancel is repeatedly rejected"],"exampleFix":"// before\nif let Err(e) = ws_client.cancel_all_orders(instrument_id, None).await {\n    anyhow::bail!(\"Cancel all orders failed: {e}\");\n}\n// after\nif let Err(e) = ws_client.cancel_all_orders(instrument_id, None).await {\n    log::error!(\"bulk cancel failed for {instrument_id}, falling back to per-order cancel: {e}\");\n    for order_id in open_order_ids(instrument_id) {\n        let _ = ws_client.cancel_order(Some(order_id), None).await;\n    }\n}","handlingStrategy":"try-catch","validationCode":"// Verify instrument validity before bulk cancel\nlet valid = instrument_cache.contains(&instrument_id);\nassert!(valid, \"unknown instrument {instrument_id}\");","typeGuard":null,"tryCatchPattern":"match client.cancel_all_orders(instrument_id, None).await {\n    Ok(()) => {}, // failure surfaces in the spawned task\n    Err(e) => log::error!(\"cancel_all dispatch failed: {e}\"),\n}\n// on failure, fall back to per-order cancels for risk reduction","preventionTips":["Never rely solely on bulk cancel for risk reduction; add per-order fallback","Confirm WebSocket auth/session health before volatile market periods","Cache and validate instrument_ids against the venue's active instruments","Log and alert on any bulk-cancel failure — it is a risk event"],"tags":["order-management","risk","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"}