{"record":{"id":"2e8fa5a0d8b2f08e","repo":"nautechsystems/nautilus_trader","slug":"instrument-symbol-not-found-in-cache-ensure-ins","errorCode":null,"errorMessage":"Instrument {symbol} not found in cache, ensure instruments loaded first","messagePattern":"Instrument (.+?) not found in cache, ensure instruments loaded first","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/adapters/bitmex/src/http/client.rs","lineNumber":1485,"sourceCode":"    /// # Errors\n    ///\n    /// Returns an error if credentials are missing, the request fails, or the API returns an error.\n    pub async fn get_orders(\n        &self,\n        params: GetOrderParams,\n    ) -> Result<Vec<BitmexOrder>, BitmexHttpError> {\n        let inner = self.inner.clone();\n        inner.get_orders(params).await\n    }\n\n    /// Get instrument from the instruments cache (if found).\n    ///\n    /// # Errors\n    ///\n    /// Returns an error if the instrument is not found in the cache.\n    fn instrument_from_cache(&self, symbol: Ustr) -> anyhow::Result<InstrumentAny> {\n        self.get_instrument(&symbol).ok_or_else(|| {\n            anyhow::anyhow!(\n                \"Instrument {symbol} not found in cache, ensure instruments loaded first\"\n            )\n        })\n    }\n\n    /// Returns the cached price precision for the given symbol.\n    ///\n    /// # Errors\n    ///\n    /// Returns an error if the instrument was never cached (for example, if\n    /// instruments were not loaded prior to use).\n    pub fn get_price_precision(&self, symbol: Ustr) -> anyhow::Result<u8> {\n        self.instrument_from_cache(symbol)\n            .map(|instrument| instrument.price_precision())\n    }\n\n    /// Get user margin information for a specific currency.\n    ///","sourceCodeStart":1467,"sourceCodeEnd":1503,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/bitmex/src/http/client.rs#L1467-L1503","documentation":"instrument_from_cache looks up a cached InstrumentAny for a BitMEX symbol and errors if it is absent. Order operations need the instrument's price precision, tick size, etc., so the client refuses to act on symbols whose instrument definitions were never loaded into the cache.","triggerScenarios":"Calling get_price_precision, submit_order, cancel_order, cancel_orders, cancel_all_orders, or modify_order with a symbol that was never added to the cache — i.e. instruments were not loaded (e.g. generate_order_status_reports/load_instruments not run) before submitting.","commonSituations":"Starting a strategy without loading instruments first, submitting orders for a newly listed or delisted BitMEX symbol, a symbol casing/format mismatch between the order and the cached instrument, or a fresh process restart with an empty cache.","solutions":["Load all instruments into the cache at startup before submitting or modifying orders.","Verify the symbol exactly matches a cached instrument symbol (use a symbol from the cache).","Add a pre-flight cache lookup for the symbol and fail fast with a clearer message.","Ensure the data client that populates instruments was initialized before the execution client is used."],"exampleFix":"// before\nclient.submit_order(order)?; // fails if symbol not cached\n// after\nif cache.instrument(&order.instrument_id()).is_none() {\n    anyhow::bail!(\"instrument {} not loaded; load instruments first\", order.instrument_id());\n}\nclient.submit_order(order)?;","handlingStrategy":"validation","validationCode":"// Rust\nif cache.instrument(&instrument_id).is_none() {\n    anyhow::bail!(\"instrument {} not loaded into cache\", instrument_id);\n}","typeGuard":"// Rust\nfn instrument_loaded(cache: &CacheView, id: InstrumentId) -> bool {\n    cache.instrument(&id).is_some()\n}","tryCatchPattern":"// Rust\nmatch client.submit_order(order).await {\n    Err(e) if e.to_string().contains(\"not found in cache\") => {\n        load_instruments(&mut cache).await?;\n        client.submit_order(order).await?\n    }\n    r => r?,\n}","preventionTips":["Load all instruments at node startup before trading","Validate symbols exist in cache before order submission","Keep instrument data warm across restarts"],"tags":["cache","instrument","order-flow","prerequisite"],"backgroundTag":"record-not-found","analyzedSha":"18893faf8b356be3320add8de2f861b0b647cf06","analyzedAt":"2026-09-08T20:49:34.690Z","contentChangedAt":"2026-09-08T20:49:34.690Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}