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
- Load/subscribe the instrument first so it is present in the cache (load_instruments or instrument refresh)
- Verify the instrument_id exactly matches the venue (correct venue name, token/condition ID format)
- Pass an explicit order_side if you only need side-scoped cancellation, bypassing the instrument lookup
- 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
- Load all traded instruments into the cache before issuing order commands
- Validate instrument IDs against venue naming (venue tag, symbol format) before sending
- Pass an explicit order_side when side-scoped cancellation is sufficient
- Refresh instruments periodically so closed/updated markets stay resolvable
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
- InstrumentLookupError::not_found(instrument_id)
- Instrument {instrument_id} not found and `auto_load_missing_
- Lighter index price subscriptions require a perpetual or spo
- Lighter fill instrument {instrument_id} missing from cache
- `tick_sz` is empty for {}
AI-assisted analysis of nautechsystems/nautilus_trader@18893faf8b (2026-09-08).
Data as JSON: /api/errors/d18d35e4e6fdfe08.
Report an issue: GitHub.