nautechsystems/nautilus_trader · error
No account events provided to create `AccountAny`
Error message
No account events provided to create `AccountAny`
What it means
`AccountAny::from_events` builds an account from a sequence of `AccountState` events; the first event initializes the account and the rest are applied as updates. If the events slice is empty there is no initializing state, so it bails with this message.
Source
Thrown at crates/model/src/accounts/any.rs:122
Account::balances(self)
}
#[must_use]
pub fn balances_locked(&self) -> IndexMap<Currency, Money> {
Account::balances_locked(self)
}
#[must_use]
pub fn base_currency(&self) -> Option<Currency> {
Account::base_currency(self)
}
/// # Errors
///
/// Returns an error if `events` is empty or an account state cannot be created or applied.
pub fn from_events(events: &[AccountState]) -> anyhow::Result<Self> {
let Some((init_event, remaining_events)) = events.split_first() else {
anyhow::bail!("No account events provided to create `AccountAny`");
};
let mut account = Self::from_state_checked(init_event.clone())?;
for event in remaining_events {
account.apply(event.clone())?;
}
Ok(account)
}
/// # Errors
///
/// Returns an error if calculating P&Ls fails for the underlying account.
pub fn calculate_pnls(
&self,
instrument: &InstrumentAny,
fill: &OrderFilled,View on GitHub (pinned to 18893faf8b)
Solutions
- Guard the call: check `!events.is_empty()` before invoking `from_events`.
- Verify the source of events (cache/backing store) actually contains account state for the account_id.
- Fix any upstream filtering/parsing that drops AccountState events.
- Ensure the account was initialized (state generated) before attempting to reconstruct it.
Example fix
// before let account = AccountAny::from_events(&events)?; // after anyhow::ensure!(!events.is_empty(), "no account events for account"); let account = AccountAny::from_events(&events)?;
Defensive patterns
Strategy: validation
Validate before calling
if events.is_empty() {
anyhow::bail!("no account events available; cannot build AccountAny");
}
let account = AccountAny::from_events(&events)?; Type guard
fn has_events(events: &[AccountState]) -> bool { !events.is_empty() } Try / catch
match AccountAny::from_events(&events) {
Err(e) if e.to_string().contains("No account events provided") => {
// handle absence of account state: skip or fetch from venue
}
r => r?,
} Prevention
- Always check the events slice is non-empty before conversion.
- Verify the backing store/cache actually persisted initial account state.
- Log event collection failures so empty slices are detected at the source.
When it happens
Trigger: Calling `AccountAny::from_events(&[])` with an empty slice — e.g. an account-state cache lookup returned nothing, or events were filtered out upstream.
Common situations: Loading account state from a backing store that has no snapshots yet (fresh environment, wrong account_id filter), or a bug collecting events before conversion.
Understand the failure class
Background: "must not be empty", "cannot be empty" — required-field validation errors across open-source libraries — this error's family across 41 libraries.
Related errors
- Timeout waiting for account {account_id} to be registered af
- BitMEX returned inconsistent margin account IDs: {account} a
- Timeout waiting for account {account_id} to be registered af
- Account {account_id} not found after cache update
- prepare_custom_data_batch called with empty data
AI-assisted analysis of nautechsystems/nautilus_trader@18893faf8b (2026-09-08).
Data as JSON: /api/errors/398779d34a7783e3.
Report an issue: GitHub.