nautechsystems/nautilus_trader · error · anyhow::Error

Cannot cancel all orders: instrument not found in cache for

Error message

Cannot cancel all orders: instrument not found in cache for {}

What it means

cancel_all_orders_command looks up the instrument for cmd.instrument_id in the execution cache to obtain its raw_symbol (market slug). If side is None and the instrument is absent from the cache, the command cannot translate the instrument to a Polymarket market and this error is returned instead of issuing cancels.

Source

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

                                "Cancel outcome unknown for {} ({}), awaiting reconciliation: {reason}",
                                order_clone.client_order_id(),
                                venue_order_id,
                            );
                        }
                    }
                    return Err(anyhow::Error::new(e).context("cancel order failed"));
                }
            }
            Ok(())
        });
    }

    pub(super) fn cancel_all_orders_command(&self, cmd: &CancelAllOrders) -> anyhow::Result<()> {
        let cache = self.core.cache();
        let side = cmd.order_side;
        let asset_id = if side.is_none() {
            let instrument = cache.instrument(&cmd.instrument_id).ok_or_else(|| {
                anyhow::anyhow!(
                    "Cannot cancel all orders: instrument not found in cache for {}",
                    cmd.instrument_id
                )
            })?;
            Some(instrument.raw_symbol().to_string())
        } else {
            None
        };
        let open_orders = cache.orders_open(
            Some(&self.core.venue),
            Some(&cmd.instrument_id),
            None,
            Some(&self.core.account_id),
            side,
        );

        if side.is_some() && open_orders.is_empty() {
            log::debug!(

View on GitHub (pinned to 18893faf8b)

Solutions

  1. Load/subscribe the instrument first so it is present in the cache (load_instruments or instrument refresh)
  2. Verify the instrument_id exactly matches the venue (correct venue name, token/condition ID format)
  3. Pass an explicit order_side if you only need side-scoped cancellation, bypassing the instrument lookup
  4. Check for typos and case in the instrument ID symbol

Example fix

// before
engine.cancel_all_orders(instrument_id=InstrumentId.from_str("BTC-YES.POLYMARKET"))  // never loaded
// after
await engine.add_instrument(poly_instrument)
engine.cancel_all_orders(instrument_id=poly_instrument.id)
Defensive patterns

Strategy: validation

Validate before calling

// Python (Nautilus): ensure the instrument exists in cache before cancel_all
from nautilus_trader.cache.cache import Cache
def can_cancel_all(cache: Cache, instrument_id) -> bool:
    return cache.instrument(instrument_id) is not None

Try / catch

try:
    exec_client.cancel_all_orders(command)
except Exception as e:
    if "instrument not found in cache" in str(e):
        raise ValueError(f"Instrument {instrument_id} not loaded; call add_instrument/load_instruments first") from e

Prevention

When it happens

Trigger: Calling cancel_all_orders with order_side = None for an instrument_id that was never loaded into the execution cache (e.g. instrument from another venue, typo'd ID, or client started before instruments were loaded/refreshed).

Common situations: Passing an instrument ID string with wrong format or venue tag; cancelling before subscription/load_instruments completed; using an ID from a stale snapshot after the market closed and was evicted.

Understand the failure class

Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.

Related errors


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