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

  1. Ensure every instrument referenced by open/persisted orders is added to the Cache (cache.add_instrument) before calling initialize_wallet_orders
  2. Audit the persisted order store for stale instrument IDs and purge orders whose instruments no longer exist
  3. Restore the full prior instrument configuration so all previously traded instruments are available at startup
  4. 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

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


AI-assisted analysis of nautechsystems/nautilus_trader@18893faf8b (2026-09-08). Data as JSON: /api/errors/6df13580915adb6b. Report an issue: GitHub.