{"record":{"id":"effe8767f01bc19d","repo":"nautechsystems/nautilus_trader","slug":"instrument-missing-from-cache-for-position-repo","errorCode":null,"errorMessage":"Instrument {} missing from cache for position report","messagePattern":"Instrument (.+?) missing from cache for position report","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/adapters/okx/src/http/client.rs","lineNumber":5395,"sourceCode":"            .get_positions(params)\n            .await\n            .map_err(|e| anyhow::anyhow!(e))?;\n\n        let ts_init = self.generate_ts_init();\n        let mut reports = Vec::with_capacity(resp.len());\n\n        for position in resp {\n            let inst = match self.resolve_report_instrument(\n                position.inst_id,\n                position.inst_type,\n                false,\n                true,\n                scope,\n            )? {\n                InstrumentResolution::Found(inst) => inst,\n                InstrumentResolution::Skip => continue,\n                InstrumentResolution::Incomplete => {\n                    anyhow::bail!(\n                        \"Instrument {} missing from cache for position report\",\n                        position.inst_id\n                    );\n                }\n            };\n\n            let report = parse_position_status_report(\n                &position,\n                account_id,\n                inst.id(),\n                inst.size_precision(),\n                ts_init,\n            )\n            .with_context(|| {\n                format!(\n                    \"failed to parse position status report for instrument {}\",\n                    position.inst_id\n                )","sourceCodeStart":5377,"sourceCodeEnd":5413,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/okx/src/http/client.rs#L5377-L5413","documentation":"This error is raised by the OKX HTTP adapter when building position reports: an instrument referenced by an OKX position (`inst_id`) could not be resolved from the local instrument cache, so a complete report cannot be produced. The adapter refuses to guess missing instrument metadata and aborts the position-report generation instead of emitting partial data.","triggerScenarios":"Calling order/position report generation (e.g. `generate_order_status_reports` / position report flows) while the OKX instrument for `position.inst_id` is absent from the adapter's instrument cache — typically because `load_cache`/instrument loading was never called, or the instrument (e.g. a newly listed or expired contract) was filtered out as out-of-scope.","commonSituations":"Starting a node with an incomplete cache before all instruments are loaded; positions on delisted or newly listed OKX instruments not in the configured instrument scope; running position reconciliation after a restart where instruments were not re-initialized.","solutions":["Ensure instruments are loaded into the cache before generating position reports (call the instrument-loading / `load_cache` path for the adapter).","Widen the instrument scope/filter so the instrument in `position.inst_id` is included in instrument loading.","Verify the `inst_id` from OKX matches a loaded instrument (check for expired/swapped contract IDs in the position).","If the instrument is genuinely unavailable, close or manually reconcile the orphaned position instead of relying on automatic reports."],"exampleFix":"// before: reports generated before instruments loaded\nadapter.generate_position_status_reports().await?;\n// after: load instruments first, then generate\nadapter.load_instruments(&fx_cache, &eq_cache).await?;\nadapter.generate_position_status_reports().await?;","handlingStrategy":"validation","validationCode":"// ensure instruments are cached before generating reports\nfor inst_id in position_instrument_ids {\n    if !cache.instrument(&inst_id).is_some() {\n        anyhow::bail!(\"pre-flight: instrument {inst_id} not in cache; load instruments first\");\n    }\n}","typeGuard":null,"tryCatchPattern":"match adapter.generate_position_status_reports().await {\n    Ok(reports) => reports,\n    Err(e) if e.to_string().contains(\"missing from cache for position report\") => {\n        adapter.load_instruments(&fx, &eq).await?;\n        adapter.generate_position_status_reports().await?\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Always load instruments (load_cache/load_instruments) before order/position report generation.","Keep the instrument scope wide enough to cover every instrument with open positions.","Re-verify cache contents after adapter restarts or config scope changes.","Log/cache-instrument mismatches on new OKX listings/expiries early in integration tests."],"tags":["okx","cache-miss","instruments","reconciliation"],"backgroundTag":"entity-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"}