{"record":{"id":"6df13580915adb6b","repo":"nautechsystems/nautilus_trader","slug":"cannot-rebuild-wallet-reservations-no-instrument","errorCode":null,"errorMessage":"cannot rebuild Wallet reservations: no instrument found for {}","messagePattern":"cannot rebuild Wallet reservations: no instrument found for (.+?)","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/portfolio/src/portfolio.rs","lineNumber":1760,"sourceCode":"\n                if !wallet_order_reserves_balance(&order) {\n                    continue;\n                }\n\n                let Some(account) = resolve_account_for_instrument(\n                    &cache,\n                    &order.instrument_id(),\n                    order.account_id().as_ref(),\n                ) else {\n                    continue;\n                };\n\n                if !matches!(&*account, AccountAny::Wallet(_)) {\n                    continue;\n                }\n\n                if cache.instrument(&order.instrument_id()).is_none() {\n                    anyhow::bail!(\n                        \"cannot rebuild Wallet reservations: no instrument found for {}\",\n                        order.instrument_id()\n                    );\n                }\n\n                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(|| {","sourceCodeStart":1742,"sourceCodeEnd":1778,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/portfolio/src/portfolio.rs#L1742-L1778","documentation":"NautilusTrader's Portfolio::initialize_wallet_orders rebuilds Wallet account order reservations after a restart by re-applying open orders. Before applying, it looks up each order's instrument in the Cache; if the instrument is absent the rebuild cannot proceed safely (reservations require instrument size/precision details), so it aborts with this error. It is a data-consistency guard: a Wallet reservation cannot be recomputed without the instrument definition.","triggerScenarios":"Calling portfolio.initialize_wallet_orders() (directly or via trader start on a Wallet-backed live/backtest node) while the Cache contains an open order whose instrument_id has no corresponding instrument loaded — e.g. adding instruments to the cache after orders were persisted, or loading order state for instruments not added via cache.add_instrument().","commonSituations":"Restarting a node with persisted orders but an instrument config that no longer lists every traded instrument; a venue/instrument definition renamed or removed between runs; loading an order store snapshot that references instruments from venues not enabled in the new config.","solutions":["Ensure every instrument referenced by open/persisted orders is added to the Cache (cache.add_instrument) before calling initialize_wallet_orders","Audit the persisted order store for stale instrument IDs and purge orders whose instruments no longer exist","Restore the full prior instrument configuration so all previously traded instruments are available at startup","If the order is genuinely obsolete, cancel/remove it from persistence before the next start"],"exampleFix":"// before: portfolio init with partial instruments\nlet portfolio = Portfolio::new(cache.clone(), clock, ...);\nportfolio.initialize_wallet_orders()?; // panics/bails: instrument missing\n// after: load all instruments first\nfor instrument in venue_instruments {\n    cache.add_instrument(instrument.clone());\n}\nportfolio.initialize_wallet_orders()?;","handlingStrategy":"validation","validationCode":"// Rust: before calling initialize_wallet_orders\nfor order in cache.orders_open() {\n    anyhow::ensure!(\n        cache.instrument(&order.instrument_id()).is_some(),\n        \"missing instrument {} needed for wallet rebuild\",\n        order.instrument_id()\n    );\n}","typeGuard":null,"tryCatchPattern":"match portfolio.initialize_wallet_orders() {\n    Err(e) if e.to_string().contains(\"no instrument found for\") => {\n        // log offending instrument id, load it into cache, retry\n    }\n    result => result?,\n}","preventionTips":["Add all instruments to the cache before restoring persisted orders","Keep instrument definitions under version control alongside the trading config","Validate persisted order instruments against the configured instrument list at startup"],"tags":["rust","portfolio","cache","wallet","missing-instrument"],"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-14T05:17:10.506Z"}