{"record":{"id":"a537ed80fdcbfb12","repo":"nautechsystems/nautilus_trader","slug":"cannot-rebuild-wallet-reservations-instrument-in","errorCode":null,"errorMessage":"cannot rebuild Wallet reservations: instrument {instrument_id} not found","messagePattern":"cannot rebuild Wallet reservations: instrument (.+?) not found","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/portfolio/src/portfolio.rs","lineNumber":1784,"sourceCode":"                grouped\n                    .entry((account.id(), order.instrument_id()))\n                    .or_default()\n                    .push((*order).clone());\n            }\n            grouped\n        };\n\n        let total_orders = grouped_orders.values().map(Vec::len).sum::<usize>();\n        for ((account_id, instrument_id), orders) in grouped_orders {\n            let (account, instrument) = {\n                let cache = self.cache.borrow();\n                let account = cache.account_owned(&account_id).ok_or_else(|| {\n                    anyhow::anyhow!(\n                        \"cannot rebuild Wallet reservations: account {account_id} not found\"\n                    )\n                })?;\n                let instrument = cache.instrument(&instrument_id).cloned().ok_or_else(|| {\n                    anyhow::anyhow!(\n                        \"cannot rebuild Wallet reservations: instrument {instrument_id} not found\"\n                    )\n                })?;\n                (account, instrument)\n            };\n            let order_refs = orders.iter().collect::<Vec<_>>();\n            let Some((updated_account, _)) = self.inner.borrow().accounts.update_orders(\n                &account,\n                &instrument,\n                &order_refs,\n                self.clock.borrow().timestamp_ns(),\n            ) else {\n                anyhow::bail!(\n                    \"cannot rebuild Wallet reservations for account {account_id} and instrument {instrument_id}\"\n                );\n            };\n            self.cache.borrow_mut().update_account(&updated_account)?;\n        }","sourceCodeStart":1766,"sourceCodeEnd":1802,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/portfolio/src/portfolio.rs#L1766-L1802","documentation":"During Wallet reservation rebuild in initialize_wallet_orders, after the account is found, the instrument for each order's InstrumentId is fetched from the cache. If the instrument definition is missing, the rebuild cannot determine price/size precisions or compute reserved values, so this error is thrown.","triggerScenarios":"Calling initialize_wallet_orders with orders whose InstrumentId is not loaded in the cache — instrument definitions never added, wrong instrument ID string (venue/symbol mismatch), or instruments purged before the call.","commonSituations":"Instrument definitions not loaded from the adapter/data catalog at startup; symbol naming differences (e.g. BTCUSDT.P vs BTCUSDT) between order and registered instrument; tests creating orders without cache.add_instrument; instruments dropped when cache is rebuilt.","solutions":["Add the instrument definition to the cache before calling initialize_wallet_orders","Verify the order's instrument_id exactly matches a registered instrument (symbol and venue)","Ensure instrument loading (e.g. from the venue adapter) completes before wallet reservation rebuild","In tests, call cache.add_instrument for every instrument used by the orders"],"exampleFix":"// before\nportfolio.initialize_wallet_orders(&orders)?;\n// after\nif cache.borrow().instrument(&instrument_id).is_none() {\n    cache.borrow_mut().add_instrument(instrument.clone());\n}\nportfolio.initialize_wallet_orders(&orders)?;","handlingStrategy":"validation","validationCode":"let instrument_present = cache.borrow().instrument(&instrument_id).is_some();\nif !instrument_present {\n    return Err(anyhow!(\"instrument {instrument_id} must be in cache before initialize_wallet_orders\"));\n}","typeGuard":null,"tryCatchPattern":"match portfolio.initialize_wallet_orders(&orders) {\n    Err(e) if e.to_string().contains(\"instrument\") && e.to_string().contains(\"not found\") => {\n        log::error!(\"missing instrument for wallet rebuild: {e:#}\");\n    }\n    other => other?,\n}","preventionTips":["Load instrument definitions from the venue adapter before strategies start","Cross-check order instrument IDs against registered instruments at config validation","In tests, always call cache.add_instrument for each instrument referenced by orders"],"tags":["cache","instrument","wallet","reservations"],"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-14T00:17:10.932Z"}