{"record":{"id":"9d31caba371af83b","repo":"nautechsystems/nautilus_trader","slug":"cancel-advance-algo-orders-failed","errorCode":null,"errorMessage":"cancel advance algo orders failed","messagePattern":"cancel advance algo orders failed","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/adapters/okx/src/execution.rs","lineNumber":1250,"sourceCode":"        }\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(\n                            classify_okx_http_failure(&e),\n                            &advance_contexts,\n                        );\n                        return Err(\n                            anyhow::Error::new(e).context(\"cancel advance algo orders failed\")\n                        );\n                    }\n                }\n                Ok(())\n            });\n        }\n    }\n\n    fn begin_generation_shutdown(&self) {\n        self.pending_tasks.begin_shutdown();\n        self.session_tasks.begin_shutdown();\n        self.ws_private.begin_shutdown();\n        self.ws_business.begin_shutdown();\n        self.core.set_disconnected();\n    }\n\n    /// Polls the cache until the account is registered or timeout is reached.\n    async fn await_account_registered(&self, timeout_secs: f64) -> anyhow::Result<()> {","sourceCodeStart":1232,"sourceCodeEnd":1268,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/okx/src/execution.rs#L1232-L1268","documentation":"The batch cancel of ADVANCE algo orders (e.g. TWAP/ Iceberg-class OKX advanced algo orders) over OKX REST failed. dispatch_algo_cancels routes advance-group orders to http_client.cancel_advance_algo_orders; an Err from that call is wrapped with this context. Per-item venue rejections on a successful response are handled separately.","triggerScenarios":"cancel_all_orders or batch_cancel_orders containing advance algo orders; http_client.cancel_advance_algo_orders returned Err: transport failure, non-2xx OKX response, auth error, rate limit, or the account lacking advance-algo trading entitlements.","commonSituations":"Canceling advanced algo orders placed outside this trader instance; OKX account not enabled for advance algo products; batch size/rate limiting on the advance endpoint; stale algo ids after process restart.","solutions":["Inspect the chained cause and logged advance_contexts to identify the failed orders.","Verify the OKX account has advance algo orders enabled and the API key can trade them.","Back off and retry if rate-limited; re-dispatch cancels for the orders listed in the failure log.","Reconcile algo order state before retrying so stale algo ids are not resubmitted."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Only cancel advance algo orders if the account supports them and they are open\nlet is_advance_open = cache.order(&cid)\n    .map(|o| is_advance_algo_order(o.order_type()) && !o.is_closed())\n    .unwrap_or(false);\nif !is_advance_open { return; }","typeGuard":null,"tryCatchPattern":"// Handle the advance-group failure distinctly from the regular group\nif let Err(e) = trader.batch_cancel_orders(batch) {\n    if format!(\"{e:#}\").contains(\"cancel advance algo orders failed\") {\n        retry_advance_cancels(advance_contexts);\n    }\n}","preventionTips":["Confirm the OKX account has advance algo orders enabled before placing them.","Only route advance-class order types to the advance cancel endpoint.","Reconcile algo state before batch cancels to avoid stale algo ids.","Watch rate limits on the advance algo endpoints separately from regular ones."],"tags":["okx","http","advance-algo","batch-cancel","permissions"],"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"}