nautechsystems/nautilus_trader · error
cannot rebuild Wallet reservations: instrument {instrument_i
Error message
cannot rebuild Wallet reservations: instrument {instrument_id} not found What it means
During Wallet reservation rebuild in initialize_wallet_orders, after the account is found, the instrument for each order's InstrumentId is fetched from the cache. If the instrument definition is missing, the rebuild cannot determine price/size precisions or compute reserved values, so this error is thrown.
Source
Thrown at crates/portfolio/src/portfolio.rs:1784
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!(
"cannot rebuild Wallet reservations for account {account_id} and instrument {instrument_id}"
);
};
self.cache.borrow_mut().update_account(&updated_account)?;
}View on GitHub (pinned to 18893faf8b)
Solutions
- Add the instrument definition to the cache before calling initialize_wallet_orders
- Verify the order's instrument_id exactly matches a registered instrument (symbol and venue)
- Ensure instrument loading (e.g. from the venue adapter) completes before wallet reservation rebuild
- In tests, call cache.add_instrument for every instrument used by the orders
Example fix
// before
portfolio.initialize_wallet_orders(&orders)?;
// after
if cache.borrow().instrument(&instrument_id).is_none() {
cache.borrow_mut().add_instrument(instrument.clone());
}
portfolio.initialize_wallet_orders(&orders)?; Defensive patterns
Strategy: validation
Validate before calling
let instrument_present = cache.borrow().instrument(&instrument_id).is_some();
if !instrument_present {
return Err(anyhow!("instrument {instrument_id} must be in cache before initialize_wallet_orders"));
} Try / catch
match portfolio.initialize_wallet_orders(&orders) {
Err(e) if e.to_string().contains("instrument") && e.to_string().contains("not found") => {
log::error!("missing instrument for wallet rebuild: {e:#}");
}
other => other?,
} Prevention
- Load instrument definitions from the venue adapter before strategies start
- Cross-check order instrument IDs against registered instruments at config validation
- In tests, always call cache.add_instrument for each instrument referenced by orders
When it happens
Trigger: Calling initialize_wallet_orders with orders whose InstrumentId is not loaded in the cache — instrument definitions never added, wrong instrument ID string (venue/symbol mismatch), or instruments purged before the call.
Common situations: Instrument definitions not loaded from the adapter/data catalog at startup; symbol naming differences (e.g. BTCUSDT.P vs BTCUSDT) between order and registered instrument; tests creating orders without cache.add_instrument; instruments dropped when cache is rebuilt.
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: account {account_id} not
- Lighter fill instrument {instrument_id} missing from cache
- cannot rebuild Wallet reservations: no instrument found for
- Instrument {instrument_id} not found in cache
- Instrument {symbol} not found in cache
AI-assisted analysis of nautechsystems/nautilus_trader@18893faf8b (2026-09-08).
Data as JSON: /api/errors/a537ed80fdcbfb12.
Report an issue: GitHub.