{"record":{"id":"4b4456cc71a5c210","repo":"nautechsystems/nautilus_trader","slug":"cancel-algo-orders-failed","errorCode":null,"errorMessage":"cancel algo orders failed","messagePattern":"cancel algo orders failed","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/adapters/okx/src/execution.rs","lineNumber":1227,"sourceCode":"\n        drop(cache);\n\n        if !regular_requests.is_empty() {\n            let client = self.http_client.clone();\n            let emitter = self.emitter.clone();\n            let clock = self.clock;\n\n            self.spawn_task(\"cancel_algo_orders\", async move {\n                match client.cancel_algo_orders(regular_requests).await {\n                    Ok(responses) => {\n                        emit_algo_cancel_rejections(&responses, &regular_contexts, &emitter, clock);\n                    }\n                    Err(e) => {\n                        log_algo_batch_cancel_failure(\n                            classify_okx_http_failure(&e),\n                            &regular_contexts,\n                        );\n                        return Err(anyhow::Error::new(e).context(\"cancel algo orders failed\"));\n                    }\n                }\n                Ok(())\n            });\n        }\n\n        if !advance_requests.is_empty() {\n            let client = self.http_client.clone();\n            let emitter = self.emitter.clone();\n            let clock = self.clock;\n\n            self.spawn_task(\"cancel_advance_algo_orders\", async move {\n                match client.cancel_advance_algo_orders(advance_requests).await {\n                    Ok(responses) => {\n                        emit_algo_cancel_rejections(&responses, &advance_contexts, &emitter, clock);\n                    }\n                    Err(e) => {\n                        log_algo_batch_cancel_failure(","sourceCodeStart":1209,"sourceCodeEnd":1245,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/okx/src/execution.rs#L1209-L1245","documentation":"The batch cancel of regular (non-advance) algo orders over OKX REST failed. dispatch_algo_cancels partitions algo cancels into regular and advance groups; this context wraps an Err from http_client.cancel_algo_orders for the regular group. Per-item rejections within a successful HTTP response are handled separately (emit_algo_cancel_rejections); this error is the whole-request failure.","triggerScenarios":"cancel_all_orders or batch_cancel_orders containing regular algo orders; http_client.cancel_algo_orders returned Err: transport failure, non-2xx response, auth error, or rate limiting on the algo-cancel endpoint.","commonSituations":"Bulk cancel of many trigger/conditional orders hitting OKX REST rate limits; API key permission issues; network outage mid-batch; mixed regular+advance orders where only the regular group failed.","solutions":["Inspect the chained cause/log classification (classify_okx_http_failure) for the failure class.","If rate-limited, back off and re-dispatch the remaining algo cancels; the contexts list in the log shows which orders still need canceling.","Retry individually per algo order to isolate any single bad request.","Verify credentials and network connectivity to OKX REST."],"exampleFix":null,"handlingStrategy":"retry","validationCode":"// Filter to algo orders that are actually open before batch cancel\nlet items: Vec<_> = algo_cids.iter()\n    .filter(|cid| cache.order(cid).map(|o| !o.is_closed()).unwrap_or(false))\n    .collect();","typeGuard":null,"tryCatchPattern":"// Batch cancel failure: re-dispatch the remaining contexts from the log\nif let Err(e) = trader.batch_cancel_orders(batch) {\n    log::warn!(\"algo batch cancel failed: {e:?}\");\n    retry_cancels_with_backoff(remaining_contexts);\n}","preventionTips":["Chunk large algo-cancel batches to stay within OKX rate limits.","Separate regular vs advance algo orders as the adapter does, to hit the right endpoint.","Retry only the contexts reported in log_algo_batch_cancel_failure.","Monitor classify_okx_http_failure output for auth vs rate-limit classes."],"tags":["okx","http","algo-orders","batch-cancel","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-14T00:17:10.932Z"}