{"record":{"id":"25e8122b2df1ecda","repo":"nautechsystems/nautilus_trader","slug":"cannot-rebuild-wallet-reservations-account-accou","errorCode":null,"errorMessage":"cannot rebuild Wallet reservations: account {account_id} not found","messagePattern":"cannot rebuild Wallet reservations: account (.+?) not found","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/portfolio/src/portfolio.rs","lineNumber":1779,"sourceCode":"                        \"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(|| {\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!(","sourceCodeStart":1761,"sourceCodeEnd":1797,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/portfolio/src/portfolio.rs#L1761-L1797","documentation":"initialize_wallet_orders rebuilds Wallet order reservations by grouping orders per (account_id, instrument_id) and looking each up in the cache. If the owning account for an order's AccountId is not present in the cache, the rebuild cannot proceed and this error is thrown. Wallet reservation accounting requires the account to compute current balances and reserved amounts.","triggerScenarios":"Calling initialize_wallet_orders with orders referencing an AccountId that was never registered in the cache, or an account that was removed before the call; calling it before the system kernel/cache has finished loading accounts.","commonSituations":"Typos or mismatched trader/account IDs in strategy config; starting strategies before accounts are registered; cache cleared or rebuilt between order creation and reservation rebuild; tests constructing orders without adding the account to the cache.","solutions":["Register the account in the cache before calling initialize_wallet_orders","Verify the account_id on the orders matches a registered account (check for typos in trader_id/account_id config)","Ensure system startup ordering: accounts must be added to the cache before wallet order initialization runs","In tests, add the owned account to the cache via cache.add_account before invoking the method"],"exampleFix":"// before\nportfolio.initialize_wallet_orders(&orders)?;\n// after\nif cache.borrow().account_owned(&account_id).is_none() {\n    cache.borrow_mut().add_account(account.clone());\n}\nportfolio.initialize_wallet_orders(&orders)?;","handlingStrategy":"validation","validationCode":"let account_present = cache.borrow().account_owned(&account_id).is_some();\nif !account_present {\n    return Err(anyhow!(\"account {account_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(\"not found\") => {\n        log::error!(\"wallet reservation rebuild skipped: {e:#}\");\n        // register missing account/instrument, then retry once\n    }\n    other => other?,\n}","preventionTips":["Register all accounts in the cache during system build, before any strategy starts","Validate account IDs in strategy config against the cache at config-load time","Never clear the cache while orders with wallet reservations are outstanding"],"tags":["cache","account","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-14T05:17:10.506Z"}