nautechsystems/nautilus_trader · error · anyhow::Error

cancel algo orders failed

Error message

cancel algo orders failed

What it means

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.

Source

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

        drop(cache);

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

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

        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(

View on GitHub (pinned to 18893faf8b)

Solutions

  1. Inspect the chained cause/log classification (classify_okx_http_failure) for the failure class.
  2. If rate-limited, back off and re-dispatch the remaining algo cancels; the contexts list in the log shows which orders still need canceling.
  3. Retry individually per algo order to isolate any single bad request.
  4. Verify credentials and network connectivity to OKX REST.
Defensive patterns

Strategy: retry

Validate before calling

// Filter to algo orders that are actually open before batch cancel
let items: Vec<_> = algo_cids.iter()
    .filter(|cid| cache.order(cid).map(|o| !o.is_closed()).unwrap_or(false))
    .collect();

Try / catch

// Batch cancel failure: re-dispatch the remaining contexts from the log
if let Err(e) = trader.batch_cancel_orders(batch) {
    log::warn!("algo batch cancel failed: {e:?}");
    retry_cancels_with_backoff(remaining_contexts);
}

Prevention

When it happens

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

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

Related errors


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