nautechsystems/nautilus_trader · error

Cancel all orders failed: {e}

Error message

Cancel all orders failed: {e}

What it means

cancel_all_orders issues a bulk cancel for a given instrument via ws_client.cancel_all_orders inside a spawned task; any failure from Deribit is logged with the instrument_id and re-raised as 'Cancel all orders failed: {e}'. The public method returns Ok(()) immediately; the failure occurs asynchronously.

Source

Thrown at crates/adapters/deribit/src/execution.rs:994

        });

        Ok(())
    }

    fn cancel_all_orders(&self, cmd: CancelAllOrders) -> anyhow::Result<()> {
        let instrument_id = cmd.instrument_id;

        // Without a side filter, use efficient bulk cancel via Deribit API
        let Some(order_side) = cmd.order_side else {
            log::debug!(
                "Cancelling all orders: instrument={instrument_id}, order_side=None (bulk)"
            );

            let ws_client = self.ws_client.clone();
            self.spawn_task("cancel_all_orders", async move {
                if let Err(e) = ws_client.cancel_all_orders(instrument_id, None).await {
                    log::error!("Cancel all orders failed for instrument {instrument_id}: {e}");
                    anyhow::bail!("Cancel all orders failed: {e}");
                }
                Ok(())
            });

            return Ok(());
        };

        // For specific side (Buy/Sell), filter from cache and cancel individually
        // Deribit API doesn't support side filtering, so we implement it locally
        log::debug!(
            "Cancelling orders by side: instrument={instrument_id}, order_side={order_side}"
        );

        let orders_to_cancel: Vec<_> = {
            let cache = self.core.cache();
            let open_orders = cache.orders_open(None, Some(&instrument_id), None, None, None);

            open_orders

View on GitHub (pinned to 18893faf8b)

Solutions

  1. Check the logged inner error and instrument_id for the venue rejection reason
  2. Verify the WebSocket connection and auth state before relying on bulk cancel for risk reduction
  3. Confirm the instrument_id is a valid, currently listed Deribit instrument
  4. Fall back to per-order cancels if bulk cancel is repeatedly rejected

Example fix

// before
if let Err(e) = ws_client.cancel_all_orders(instrument_id, None).await {
    anyhow::bail!("Cancel all orders failed: {e}");
}
// after
if let Err(e) = ws_client.cancel_all_orders(instrument_id, None).await {
    log::error!("bulk cancel failed for {instrument_id}, falling back to per-order cancel: {e}");
    for order_id in open_order_ids(instrument_id) {
        let _ = ws_client.cancel_order(Some(order_id), None).await;
    }
}
Defensive patterns

Strategy: try-catch

Validate before calling

// Verify instrument validity before bulk cancel
let valid = instrument_cache.contains(&instrument_id);
assert!(valid, "unknown instrument {instrument_id}");

Try / catch

match client.cancel_all_orders(instrument_id, None).await {
    Ok(()) => {}, // failure surfaces in the spawned task
    Err(e) => log::error!("cancel_all dispatch failed: {e}"),
}
// on failure, fall back to per-order cancels for risk reduction

Prevention

When it happens

Trigger: Calling cancel_all_orders(instrument_id) when the Deribit bulk cancel-by-instrument request fails — instrument not recognized, no active session/auth, connection drop, or Deribit-side rejection.

Common situations: Flatten-all risk flows during volatility when the WebSocket is degraded; using an instrument_id not currently listed on Deribit; unauthenticated private session after reconnect.

Related errors


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