nautechsystems/nautilus_trader · error · anyhow::Error

cancel advance algo orders failed

Error message

cancel advance algo orders failed

What it means

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.

Source

Thrown at crates/adapters/okx/src/execution.rs:1250

        }

        if !advance_requests.is_empty() {
            let client = self.http_client.clone();
            let emitter = self.emitter.clone();
            let clock = self.clock;

            self.spawn_task("cancel_advance_algo_orders", async move {
                match client.cancel_advance_algo_orders(advance_requests).await {
                    Ok(responses) => {
                        emit_algo_cancel_rejections(&responses, &advance_contexts, &emitter, clock);
                    }
                    Err(e) => {
                        log_algo_batch_cancel_failure(
                            classify_okx_http_failure(&e),
                            &advance_contexts,
                        );
                        return Err(
                            anyhow::Error::new(e).context("cancel advance algo orders failed")
                        );
                    }
                }
                Ok(())
            });
        }
    }

    fn begin_generation_shutdown(&self) {
        self.pending_tasks.begin_shutdown();
        self.session_tasks.begin_shutdown();
        self.ws_private.begin_shutdown();
        self.ws_business.begin_shutdown();
        self.core.set_disconnected();
    }

    /// Polls the cache until the account is registered or timeout is reached.
    async fn await_account_registered(&self, timeout_secs: f64) -> anyhow::Result<()> {

View on GitHub (pinned to 18893faf8b)

Solutions

  1. Inspect the chained cause and logged advance_contexts to identify the failed orders.
  2. Verify the OKX account has advance algo orders enabled and the API key can trade them.
  3. Back off and retry if rate-limited; re-dispatch cancels for the orders listed in the failure log.
  4. Reconcile algo order state before retrying so stale algo ids are not resubmitted.
Defensive patterns

Strategy: validation

Validate before calling

// Only cancel advance algo orders if the account supports them and they are open
let is_advance_open = cache.order(&cid)
    .map(|o| is_advance_algo_order(o.order_type()) && !o.is_closed())
    .unwrap_or(false);
if !is_advance_open { return; }

Try / catch

// Handle the advance-group failure distinctly from the regular group
if let Err(e) = trader.batch_cancel_orders(batch) {
    if format!("{e:#}").contains("cancel advance algo orders failed") {
        retry_advance_cancels(advance_contexts);
    }
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of nautechsystems/nautilus_trader@18893faf8b (2026-09-08). Data as JSON: /api/errors/9d31caba371af83b. Report an issue: GitHub.