nautechsystems/nautilus_trader · error · anyhow::Error

failed to cancel all orders

Error message

failed to cancel all orders

What it means

Polymarket's cancel_all_orders_command sends a bulk cancel-all request to the CLOB API. On an Err response it applies the HTTP failure to each order (emitting denied/failed events) and returns "failed to cancel all orders". It indicates the venue-level cancel-all did not succeed.

Source

Thrown at crates/adapters/polymarket/src/execution/cancellations.rs:413

                        } else {
                            log::debug!(
                                "Cancel-all response omitted local order {} ({})",
                                order.client_order_id(),
                                venue_order_id
                            );
                        }
                    }

                    log::debug!(
                        "Cancel-all completed for instrument_id={instrument_id}: canceled={}, not_canceled={}",
                        response.canceled.len(),
                        response.not_canceled.len()
                    );
                    Ok(())
                }
                Err(e) => {
                    apply_cancel_http_failure(&e, &orders, &emitter, clock);
                    Err(anyhow::Error::new(e).context("failed to cancel all orders"))
                }
            }
        });
        anyhow::ensure!(spawned, "Polymarket execution client is shutting down");

        Ok(())
    }

    pub(super) fn batch_cancel_orders_command(&self, cmd: &BatchCancelOrders) {
        if cmd.cancels.is_empty() {
            return;
        }

        let mut orders = Vec::new();

        for c in &cmd.cancels {
            if let Some(order) = self.core.cache().order(&c.client_order_id) {
                orders.push(order.clone());

View on GitHub (pinned to 18893faf8b)

Solutions

  1. Read the wrapped underlying error for the HTTP status / CLOB error code.
  2. Verify Polymarket API credentials and nonce synchronization; refresh API keys.
  3. Retry after a backoff if the cause is rate limiting or transient service unavailability.
  4. Fall back to per-order cancels for instruments where cancel-all failed.
  5. Check network/proxy connectivity to the CLOB endpoint.
Defensive patterns

Strategy: retry

Validate before calling

// verify endpoint reachability and credentials before bulk cancel
assert!(clob_health_check().is_ok(), "CLOB endpoint reachable");
assert!(!api_key_expired(), "credentials valid");

Try / catch

if let Err(e) = client.cancel_all_orders(&instrument_id, side) {
    warn!("cancel-all failed: {e}");
    sleep_exponential_backoff();
    client.cancel_all_orders(&instrument_id, side)?;
}

Prevention

When it happens

Trigger: Calling cancel_all_orders when the Polymarket CLOB bulk-cancel HTTP call fails: auth rejection, network failure, non-2xx response, or service unavailability. Note the failure is applied per-order via apply_cancel_http_failure before the error is returned.

Common situations: Polymarket CLOB downtime or degraded service; expired API credentials/nonce desync; proxy or firewall blocking the endpoint; rate limiting after heavy cancel traffic.

Understand the failure class

Background: "API error: {status}" and "HTTP 401/403/404/429/5xx" errors: non-2xx HTTP responses explained — this error's family across 27 libraries.

Related errors


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