{"record":{"id":"38a53833ed69c34d","repo":"nautechsystems/nautilus_trader","slug":"instrument-symbol-not-in-cache-38a538","errorCode":null,"errorMessage":"Instrument {symbol} not in cache","messagePattern":"Instrument (.+?) not in cache","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/adapters/okx/src/http/client.rs","lineNumber":2171,"sourceCode":"                retry_delay_ms,\n                retry_delay_max_ms,\n                environment,\n                proxy_url,\n            )?),\n            instruments_cache: Arc::new(AtomicMap::new()),\n            cache_initialized: AtomicBool::new(false),\n        })\n    }\n\n    /// Retrieves an instrument from the cache.\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.instruments_cache\n            .get_cloned(&symbol)\n            .ok_or_else(|| anyhow::anyhow!(\"Instrument {symbol} not in cache\"))\n    }\n\n    fn instrument_from_cache_by_id(\n        &self,\n        instrument_id: InstrumentId,\n    ) -> anyhow::Result<InstrumentAny> {\n        self.instruments_cache\n            .get_cloned(&instrument_id.symbol.inner())\n            .ok_or_else(|| InstrumentLookupError::not_found(instrument_id).into())\n    }\n\n    /// Cancel all pending HTTP requests.\n    pub fn cancel_all_requests(&self) {\n        self.inner.cancel_all_requests();\n    }\n\n    /// Get the cancellation token for this client.\n    pub fn cancellation_token(&self) -> &CancellationToken {","sourceCodeStart":2153,"sourceCodeEnd":2189,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/okx/src/http/client.rs#L2153-L2189","documentation":"OKXHttpClient::instrument_from_cache looks up an instrument by symbol in the client's local instruments cache; when absent it errors with `Instrument {symbol} not in cache`. The adapter requires instruments to be pre-loaded before requests that need conversions or definitions.","triggerScenarios":"Any HTTP client operation that calls instrument_from_cache with a symbol that was never added via the instrument loading/unsubscribe cycle — e.g. requesting data for an instrument that was not part of the configured instrument_ids.","commonSituations":"Requesting trades/book for a symbol not in the client's configured instruments; typo'd or stale instrument symbols; using a symbol from a different venue; cache cleared or never populated before first request.","solutions":["Load the instrument into the cache first (call the client's instrument loading path for that symbol/instrument_id).","Verify the symbol string matches an OKX instrument exactly (e.g. BTC-USDT, BTC-USDT-SWAP).","Add the instrument_id to the client configuration so it is populated during initialization.","Check that you are using the same cache instance the client was built with."],"exampleFix":"// before\nlet inst = client.instrument_from_cache(symbol)?; // panics-free but errors if absent\n// after\nif !client.has_instrument(symbol) {\n    client.load_instrument(&instrument_id).await?;\n}\nlet inst = client.instrument_from_cache(symbol)?;","handlingStrategy":"validation","validationCode":"let loaded: Vec<InstrumentId> = client.instruments();\nif !loaded.contains(&instrument_id) {\n    client.load_instrument(&instrument_id).await?;\n}","typeGuard":null,"tryCatchPattern":"match client.instrument_from_cache(symbol) {\n    Ok(inst) => inst,\n    Err(e) if e.to_string().contains(\"not in cache\") => {\n        client.load_instrument(&instrument_id).await?;\n        client.instrument_from_cache(symbol)?\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Always load all instruments you intend to query during client initialization.","Validate symbols against OKX naming (BTC-USDT, BTC-USDT-SWAP) before requests.","Avoid sharing symbol strings across venues without conversion."],"tags":["rust","cache","okx","instrument"],"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-14T00:17:10.932Z"}