nautechsystems/nautilus_trader · error · anyhow::Error
cannot rebuild Wallet reservations: no instrument found for
Error message
cannot rebuild Wallet reservations: no instrument found for {} What it means
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.
Source
Thrown at crates/portfolio/src/portfolio.rs:1760
if !wallet_order_reserves_balance(&order) {
continue;
}
let Some(account) = resolve_account_for_instrument(
&cache,
&order.instrument_id(),
order.account_id().as_ref(),
) else {
continue;
};
if !matches!(&*account, AccountAny::Wallet(_)) {
continue;
}
if cache.instrument(&order.instrument_id()).is_none() {
anyhow::bail!(
"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(|| {View on GitHub (pinned to 18893faf8b)
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
Example fix
// before: portfolio init with partial instruments
let portfolio = Portfolio::new(cache.clone(), clock, ...);
portfolio.initialize_wallet_orders()?; // panics/bails: instrument missing
// after: load all instruments first
for instrument in venue_instruments {
cache.add_instrument(instrument.clone());
}
portfolio.initialize_wallet_orders()?; Defensive patterns
Strategy: validation
Validate before calling
// Rust: before calling initialize_wallet_orders
for order in cache.orders_open() {
anyhow::ensure!(
cache.instrument(&order.instrument_id()).is_some(),
"missing instrument {} needed for wallet rebuild",
order.instrument_id()
);
} Try / catch
match portfolio.initialize_wallet_orders() {
Err(e) if e.to_string().contains("no instrument found for") => {
// log offending instrument id, load it into cache, retry
}
result => result?,
} Prevention
- 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
When it happens
Trigger: 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().
Common situations: 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.
Understand the failure class
Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.
Related errors
- Cannot cache futures spread: missing option instrument {call
- Cannot cache futures spread: missing option instrument {put_
- cannot rebuild Wallet reservations for account {account_id}
- DataActor {} must be registered before calling `cache()` - t
- Order {client_order_id} not found
AI-assisted analysis of nautechsystems/nautilus_trader@18893faf8b (2026-09-08).
Data as JSON: /api/errors/6df13580915adb6b.
Report an issue: GitHub.