nautechsystems/nautilus_trader · error
cannot rebuild Wallet reservations: account {account_id} not
Error message
cannot rebuild Wallet reservations: account {account_id} not found What it means
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.
Source
Thrown at crates/portfolio/src/portfolio.rs:1779
"cannot rebuild Wallet reservations: no instrument found for {}",
order.instrument_id()
);
}
grouped
.entry((account.id(), order.instrument_id()))
.or_default()
.push((*order).clone());
}
grouped
};
let total_orders = grouped_orders.values().map(Vec::len).sum::<usize>();
for ((account_id, instrument_id), orders) in grouped_orders {
let (account, instrument) = {
let cache = self.cache.borrow();
let account = cache.account_owned(&account_id).ok_or_else(|| {
anyhow::anyhow!(
"cannot rebuild Wallet reservations: account {account_id} not found"
)
})?;
let instrument = cache.instrument(&instrument_id).cloned().ok_or_else(|| {
anyhow::anyhow!(
"cannot rebuild Wallet reservations: instrument {instrument_id} not found"
)
})?;
(account, instrument)
};
let order_refs = orders.iter().collect::<Vec<_>>();
let Some((updated_account, _)) = self.inner.borrow().accounts.update_orders(
&account,
&instrument,
&order_refs,
self.clock.borrow().timestamp_ns(),
) else {
anyhow::bail!(View on GitHub (pinned to 18893faf8b)
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
Example fix
// before
portfolio.initialize_wallet_orders(&orders)?;
// after
if cache.borrow().account_owned(&account_id).is_none() {
cache.borrow_mut().add_account(account.clone());
}
portfolio.initialize_wallet_orders(&orders)?; Defensive patterns
Strategy: validation
Validate before calling
let account_present = cache.borrow().account_owned(&account_id).is_some();
if !account_present {
return Err(anyhow!("account {account_id} must be in cache before initialize_wallet_orders"));
} Try / catch
match portfolio.initialize_wallet_orders(&orders) {
Err(e) if e.to_string().contains("not found") => {
log::error!("wallet reservation rebuild skipped: {e:#}");
// register missing account/instrument, then retry once
}
other => other?,
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: "Not found" and "does not exist" errors: why "Task not found", "No such folder", and "Can't find" fire when a lookup comes back empty — this error's family across 14 libraries.
Related errors
- cannot rebuild Wallet reservations: instrument {instrument_i
- Account {account_id} not found after cache update
- delete_account_event not implemented for PostgreSQL cache ad
- cannot rebuild Wallet reservations: no instrument found for
- Cannot persist account with no events: {}
AI-assisted analysis of nautechsystems/nautilus_trader@18893faf8b (2026-09-08).
Data as JSON: /api/errors/25e8122b2df1ecda.
Report an issue: GitHub.