{"record":{"id":"d18d35e4e6fdfe08","repo":"nautechsystems/nautilus_trader","slug":"cannot-cancel-all-orders-instrument-not-found-in","errorCode":null,"errorMessage":"Cannot cancel all orders: instrument not found in cache for {}","messagePattern":"Cannot cancel all orders: instrument not found in cache for (.+?)","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/adapters/polymarket/src/execution/cancellations.rs","lineNumber":283,"sourceCode":"                                \"Cancel outcome unknown for {} ({}), awaiting reconciliation: {reason}\",\n                                order_clone.client_order_id(),\n                                venue_order_id,\n                            );\n                        }\n                    }\n                    return Err(anyhow::Error::new(e).context(\"cancel order failed\"));\n                }\n            }\n            Ok(())\n        });\n    }\n\n    pub(super) fn cancel_all_orders_command(&self, cmd: &CancelAllOrders) -> anyhow::Result<()> {\n        let cache = self.core.cache();\n        let side = cmd.order_side;\n        let asset_id = if side.is_none() {\n            let instrument = cache.instrument(&cmd.instrument_id).ok_or_else(|| {\n                anyhow::anyhow!(\n                    \"Cannot cancel all orders: instrument not found in cache for {}\",\n                    cmd.instrument_id\n                )\n            })?;\n            Some(instrument.raw_symbol().to_string())\n        } else {\n            None\n        };\n        let open_orders = cache.orders_open(\n            Some(&self.core.venue),\n            Some(&cmd.instrument_id),\n            None,\n            Some(&self.core.account_id),\n            side,\n        );\n\n        if side.is_some() && open_orders.is_empty() {\n            log::debug!(","sourceCodeStart":265,"sourceCodeEnd":301,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/polymarket/src/execution/cancellations.rs#L265-L301","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","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"],"exampleFix":"// before\nengine.cancel_all_orders(instrument_id=InstrumentId.from_str(\"BTC-YES.POLYMARKET\"))  // never loaded\n// after\nawait engine.add_instrument(poly_instrument)\nengine.cancel_all_orders(instrument_id=poly_instrument.id)","handlingStrategy":"validation","validationCode":"// Python (Nautilus): ensure the instrument exists in cache before cancel_all\nfrom nautilus_trader.cache.cache import Cache\ndef can_cancel_all(cache: Cache, instrument_id) -> bool:\n    return cache.instrument(instrument_id) is not None","typeGuard":null,"tryCatchPattern":"try:\n    exec_client.cancel_all_orders(command)\nexcept Exception as e:\n    if \"instrument not found in cache\" in str(e):\n        raise ValueError(f\"Instrument {instrument_id} not loaded; call add_instrument/load_instruments first\") from e","preventionTips":["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"],"tags":["rust","cache-miss","instrument","polymarket"],"backgroundTag":"resource-not-found","analyzedSha":"18893faf8b356be3320add8de2f861b0b647cf06","analyzedAt":"2026-09-08T20:49:34.690Z","contentChangedAt":"2026-09-08T20:49:34.690Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}