{"record":{"id":"2e9a3b6181530e13","repo":"nautechsystems/nautilus_trader","slug":"mass-cancel-orders-failed","errorCode":null,"errorMessage":"mass cancel orders failed","messagePattern":"mass cancel orders failed","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/adapters/okx/src/execution.rs","lineNumber":1112,"sourceCode":"\n                        if is_rejected {\n                            anyhow::bail!(\"{reason}\");\n                        }\n                    }\n                }\n            }\n\n            Ok(())\n        });\n    }\n\n    fn mass_cancel_instrument(&self, instrument_id: InstrumentId) {\n        if is_spread_instrument(instrument_id) {\n            let http_client = self.http_client.clone();\n            self.spawn_task(\"mass_cancel_orders_http\", async move {\n                if let Err(e) = http_client.cancel_all_orders(instrument_id).await {\n                    log_mass_cancel_failure(classify_okx_http_failure(&e), instrument_id);\n                    return Err(anyhow::Error::new(e).context(\"mass cancel orders failed\"));\n                }\n                Ok(())\n            });\n            return;\n        }\n\n        let ws_private = self.ws_private.clone();\n\n        self.spawn_task(\"mass_cancel_orders\", async move {\n            if let Err(e) = ws_private.mass_cancel_orders(instrument_id).await {\n                log_mass_cancel_failure(classify_okx_ws_failure(&e), instrument_id);\n                return Err(anyhow::Error::new(e).context(\"mass cancel orders failed\"));\n            }\n            Ok(())\n        });\n    }\n\n    /// Populates `order_identities` for an order if not already present.","sourceCodeStart":1094,"sourceCodeEnd":1130,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/okx/src/execution.rs#L1094-L1130","documentation":"Mass cancel (cancel all open orders) for an instrument failed on the OKX REST endpoint — the branch used for spread instruments. http_client.cancel_all_orders returned Err, the failure is logged with a classification, and the task returns 'mass cancel orders failed' with the cause chained.","triggerScenarios":"cancel_all_orders on a spread instrument; http_client.cancel_all_orders(instrument_id) returned Err: HTTP transport failure, non-2xx OKX response, auth failure, or venue-side rejection of the mass-cancel request.","commonSituations":"Bulk flat before a session close on spread instruments; OKX rate limiting from many mass cancels; API key without trade permission; network outage to OKX REST; instrument id format mismatch after a symbol change.","solutions":["Check the classified failure in the log and the chained cause for the OKX error code.","Verify API key trade permission and live/demo domain correctness.","If rate-limited (429), back off and retry the mass cancel, or cancel orders individually.","Confirm network/proxy connectivity to OKX REST and that the instrument id is still valid on OKX."],"exampleFix":null,"handlingStrategy":"retry","validationCode":"// Check REST reachability and credentials before bulk cancels\n// (configuration check) ensure OKX_API_KEY/SECRET/PASSPHRASE set and domain matches env","typeGuard":null,"tryCatchPattern":"// Retry mass cancel with backoff, then fall back to per-order HTTP cancels\nif let Err(e) = trader.cancel_all_orders(instrument_id) {\n    log::warn!(\"mass cancel failed: {e:?}; falling back to per-order cancels\");\n    for cid in open_order_ids(instrument_id) { trader.cancel_order(cid); }\n}","preventionTips":["Throttle bulk cancel operations to avoid OKX REST rate limits.","Verify API key trade permission before mass-cancel windows.","Confirm spread instrument ids are valid on OKX (symbol/format changes).","Fall back to per-order cancels when mass cancel endpoints fail."],"tags":["okx","http","mass-cancel","spread","network"],"backgroundTag":"http-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"}