{"record":{"id":"ed8d26dd84415098","repo":"nautechsystems/nautilus_trader","slug":"ws-cancel-order-failed-e","errorCode":null,"errorMessage":"WS cancel order failed: {e}","messagePattern":"WS cancel order failed: (.+?)","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"critical","filePath":"crates/adapters/binance/src/futures/execution.rs","lineNumber":845,"sourceCode":"            // Pre-register before sending to avoid response racing the insert\n            let request_id = ws_client.next_request_id();\n            dispatch_state.pending_requests.insert(\n                request_id.clone(),\n                PendingRequest {\n                    client_order_id,\n                    venue_order_id,\n                    operation: PendingOperation::Cancel,\n                },\n            );\n\n            self.spawn_task(\"cancel_order_ws\", async move {\n                if let Err(e) = ws_client\n                    .cancel_order_with_id(request_id.clone(), params)\n                    .await\n                {\n                    dispatch_state.pending_requests.remove(&request_id);\n                    log::error!(\"WS cancel request failed for {client_order_id}: {e}\");\n                    anyhow::bail!(\"WS cancel order failed: {e}\");\n                }\n                Ok(())\n            });\n\n            return;\n        }\n\n        let http_client = self.http_client.clone();\n\n        self.spawn_task(\"cancel_order\", async move {\n            let result = if use_algo_cancel {\n                // Try algo cancel first; if it fails, the order may have been triggered\n                // before this session started, so fall back to regular cancel\n                match http_client.cancel_algo_order(client_order_id).await {\n                    Ok(()) => Ok(()),\n                    Err(algo_err) => {\n                        log::debug!(\"Algo cancel failed, trying regular cancel: {algo_err}\");\n                        http_client","sourceCodeStart":827,"sourceCodeEnd":863,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/a4b06ed870971b5671d12754ea138a3ab99b1dec/crates/adapters/binance/src/futures/execution.rs#L827-L863","documentation":"Raised inside the spawned cancel_order_ws task when the Binance WebSocket API cancel_order_with_id call fails. The client removes the cancel's pending request, logs 'WS cancel request failed for {client_order_id}', and bails with this message wrapping the venue error. Because the cancel did not reach the exchange, the order may still be live — treat this as a risk-relevant failure, not a cleanup detail.","triggerScenarios":"Cancelling over the WS order channel with an unknown/already-filled order id (-2011 Unknown order sent), during a WS reconnect window, under cancel-rate limits, or with params rejected by the venue (e.g. cancel-replace race already resolved).","commonSituations":"Cancel bursts during volatility tripping rate limits; cancels racing order fills; WS session expiry between submit and cancel; reconciliation loops cancelling stale orders that no longer exist.","solutions":["Read the embedded WS error code in the logged {e}: -2011 means the order is already filled/cancelled and the state should be reconciled, not retried","Verify the order is actually open (order status reports) before retrying the cancel","Throttle cancels within venue limits; batch cancel where available","If WS errors persist, check connection health or use the HTTP cancel path if configured"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// Only attempt a cancel when the order is live:\nif matches!(order.status(), OrderStatus::Accepted | OrderStatus::Triggered | OrderStatus::PendingUpdate) {\n    client.cancel_order(order.clone()).await?;\n}","typeGuard":null,"tryCatchPattern":"// cancel failures are async: on OrderCanceled absence + 'WS cancel request failed' log,\n//   - error -2011 (unknown order): reconcile status, do NOT retry\n//   - rate limit / transient: retry once after backoff\n//   - still live after retry: escalate (flatten via reduce-only order) per risk policy","preventionTips":["Track expected order state and reconcile with order-status reports after cancel failures","Throttle cancel bursts inside venue limits","Prefer batch-cancel APIs for teardowns","Treat a failed cancel as a live-order incident, not a logging event"],"tags":["binance-futures","order-cancel","websocket","execution","rust"],"backgroundTag":"order-cancel-failed","analyzedSha":"a4b06ed870971b5671d12754ea138a3ab99b1dec","analyzedAt":"2026-08-16T22:54:50.089Z","schemaVersion":2},"datasetVersion":"2026-08-16T23:17:17.608Z"}