nautechsystems/nautilus_trader · error

Account event had a different account ID: expected {}, recei

Error message

Account event had a different account ID: expected {}, received {}

What it means

An AccountState event was applied to an Account whose account_id does not match the event's account_id. The library guards against applying another account's state to this account, ensuring events are never partially or incorrectly applied. Raised by the internal `check_event_account_id` check.

Source

Thrown at crates/model/src/accounts/base.rs:242

        self.commissions.get(currency).copied()
    }

    /// Returns a map of all commissions by currency.
    #[must_use]
    pub fn commissions(&self) -> AHashMap<Currency, Money> {
        self.commissions.clone()
    }

    /// Checks the event belongs to this account.
    ///
    /// Concrete accounts call this before mutating any state, so a foreign event is rejected
    /// rather than partially applied.
    ///
    /// # Errors
    ///
    /// Returns an error if `event.account_id` does not match this account's ID.
    pub(crate) fn check_event_account_id(&self, event: &AccountState) -> anyhow::Result<()> {
        anyhow::ensure!(
            event.account_id == self.id,
            "Account event had a different account ID: expected {}, received {}",
            self.id,
            event.account_id
        );
        Ok(())
    }

    /// Applies an [`AccountState`] event, updating balances.
    ///
    /// # Panics
    ///
    /// Panics if `event.account_id` does not match this account's ID. Every account rejects a
    /// foreign event before reaching here, so this remains an internal invariant.
    pub fn base_apply(&mut self, event: AccountState) {
        check_equal(&event.account_id, &self.id, "event.account_id", "self.id").expect(FAILED);
        self.update_balances(&event.balances);
        self.events.push(event);

View on GitHub (pinned to 18893faf8b)

Solutions

  1. Check the adapter's account ID generation to confirm the event's account_id matches the account it is dispatched to
  2. Verify only one account instance is registered per account_id in the cache
  3. Re-run/reconcile with events from the correct account source
Defensive patterns

Strategy: validation

Validate before calling

if event.account_id != account.id:
    log.error(f"event for {event.account_id} routed to {account.id}; dropping")
    return

Try / catch

try:
    account.apply(event)
except Exception as e:
    log.error(f"account event rejected: {e}")

Prevention

When it happens

Trigger: Routing an AccountState event for account X to the Account object for account Y — typically when an adapter emits events with a mismatched or reformatted account ID, or when events are dispatched to the wrong registered account.

Common situations: Broker adapter generating account IDs that change format across sessions, multiple accounts configured and events mixed up during replay, or event cache/actor wiring sending events to the wrong account handler.

Understand the failure class

Background: "Invalid state transition" errors: "status must be X, actually Y", "already rejected/charging/uninstalled", "cannot ... while running" — what they mean when a library rejects your call — this error's family across 31 libraries.

Related errors


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