{"record":{"id":"53c4a93e6330f474","repo":"nautechsystems/nautilus_trader","slug":"batch-cancel-order-failed-e","errorCode":null,"errorMessage":"Batch cancel order failed: {e}","messagePattern":"Batch cancel order failed: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/adapters/deribit/src/execution.rs","lineNumber":1113,"sourceCode":"            let trader_id = cancel.trader_id;\n            let strategy_id = cancel.strategy_id;\n            let instrument_id = cancel.instrument_id;\n\n            self.spawn_task(\"batch_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                        \"Batch cancel order failed: order_id={order_id}, client_order_id={client_order_id}, error={e}\"\n                    );\n                    anyhow::bail!(\"Batch cancel order failed: {e}\");\n                }\n                Ok(())\n            });\n        }\n\n        Ok(())\n    }\n}\n\n/// Dispatches a WebSocket message using the event emitter.\nfn dispatch_ws_message(message: NautilusWsMessage, emitter: &ExecutionEventEmitter) {\n    match message {\n        NautilusWsMessage::AccountState(state) => {\n            emitter.send_account_state(state);\n        }\n        NautilusWsMessage::OrderStatusReports(reports) => {\n            log::debug!(\"Processing {} order status report(s)\", reports.len());\n            for report in reports {","sourceCodeStart":1095,"sourceCodeEnd":1131,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/deribit/src/execution.rs#L1095-L1131","documentation":"batch_cancel_orders splits a batch into per-order spawned tasks; when an individual cancel request fails for a specific order_id/client_order_id, the error is logged and re-raised as 'Batch cancel order failed: {e}' within that order's task. Other orders in the batch continue independently, so this error is per-order, not batch-wide.","triggerScenarios":"Calling batch_cancel_orders where one or more individual orders cannot be cancelled — unknown/stale order ID, already filled/cancelled order, rate limiting across the batch, or connection issues.","commonSituations":"Large batches hitting Deribit rate limits; stale IDs from a previous session; mixed results where some cancels succeed and others fail, making reconciliation confusing.","solutions":["Match the failed order_id/client_order_id from the log to identify which orders need retry","Check Deribit rate limits and throttle batch submissions for large order sets","Verify each order's open state; skip orders already filled or cancelled","Retry only the failed subset after connectivity is confirmed"],"exampleFix":"// before\nif let Err(e) = ws_client.batch_cancel_orders(order_ids).await {\n    anyhow::bail!(\"Batch cancel order failed: {e}\");\n}\n// after\nfor chunk in order_ids.chunks(10) {\n    tokio::time::sleep(Duration::from_millis(100)).await; // respect rate limits\n    if let Err(e) = ws_client.batch_cancel_orders(chunk.to_vec()).await {\n        log::warn!(\"partial batch cancel failed, will reconcile: {e}\");\n        failed_ids.extend(chunk.iter().cloned());\n    }\n}","handlingStrategy":"try-catch","validationCode":"// Pre-filter batch to orders known open and throttle batch size\nlet batch: Vec<_> = order_ids.iter().filter(|id| open_orders.contains(id)).collect();\nassert!(batch.len() <= 20, \"batch too large, risk of rate limiting\");","typeGuard":null,"tryCatchPattern":"match client.batch_cancel_orders(ids).await {\n    Ok(()) => {},\n    Err(e) => {\n        log::warn!(\"batch cancel partial failure: {e}\");\n        reconcile_open_orders_against_venue();\n    }\n}","preventionTips":["Reconcile local open orders against the venue before large batch cancels","Chunk batches and add delays to respect Deribit rate limits","Expect partial failures: treat this error as per-order and retry only failed IDs","Purge stale order IDs after reconnects"],"tags":["order-management","batch","deribit","rate-limit"],"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"}