nautechsystems/nautilus_trader · error · anyhow::Error

Cannot generate {operation} event for {order.client_order_id

Error message

Cannot generate {operation} event for {order.client_order_id()}: account_id is not set

What it means

Raised by `required_account_id` when an order has no account_id set, so the strategy cannot generate the required order event (pending update / pending cancel) that references an account. Account_id is normally assigned during submission via the execution client.

Source

Thrown at crates/trading/src/strategy/mod.rs:2448

        log::info!("{id} {CMD}{SEND} {command}");
    } else {
        log::info!("{CMD}{SEND} {command}");
    }
}

fn registered_trader_id(core: &StrategyCore) -> anyhow::Result<TraderId> {
    core.trader_id()
        .ok_or_else(|| anyhow::anyhow!("Strategy not registered: trader_id is not set"))
}

fn registered_strategy_id(core: &StrategyCore) -> anyhow::Result<StrategyId> {
    core.strategy_id()
        .ok_or_else(|| anyhow::anyhow!("Strategy not registered: strategy_id is not set"))
}

fn required_account_id(order: &OrderAny, operation: &str) -> anyhow::Result<AccountId> {
    order.account_id().ok_or_else(|| {
        anyhow::anyhow!(
            "Cannot generate {operation} event for {}: account_id is not set",
            order.client_order_id()
        )
    })
}

#[cfg(test)]
mod tests {
    use std::{cell::RefCell, rc::Rc};

    use nautilus_common::{
        actor::{
            DataActor,
            registry::{deregister_actor, try_get_actor_unchecked},
        },
        cache::{Cache, ORDER_NOT_FOUND},
        clock::{Clock, TestClock},
        component::{Component, deregister_component, register_component_actor},

View on GitHub (pinned to 18893faf8b)

Solutions

  1. Set account_id when constructing or importing orders (order.set_account_id / correct submission path).
  2. Only route orders to mark_pending_* that were submitted through the strategy's execution client.
  3. For external orders, wait for the reconciliation/event that attaches account_id before generating strategy events.
  4. Fix test fixtures to include a valid AccountId.

Example fix

// before
let order = OrderAny::new(TestOrderStub::default(), UUID4::new());
strategy.cancel_order(&order.client_order_id())?;
// after
let mut order = OrderAny::new(TestOrderStub::default(), UUID4::new());
order.set_account_id(account_id);
strategy.cancel_order(&order.client_order_id())?;
Defensive patterns

Strategy: validation

Validate before calling

if order.account_id().is_none() {
    return Err(format!("order {} has no account_id; cannot generate strategy event", order.client_order_id()));
}

Try / catch

if let Err(e) = strategy.cancel_order(&order.client_order_id()) {
    if e.to_string().contains("account_id is not set") { log::warn!("skipping external order without account: {e}"); }
}

Prevention

When it happens

Trigger: Calling mark_order_pending_update or mark_order_pending_cancel on an order that lacks an account_id — typically externally created orders injected into the cache without account info, or orders built manually with OrderAny::new without account_id.

Common situations: Handling external order fills (e.g. from a different venue session) in an emulated/tracked strategy, manually constructed OrderAny in tests (the test test_required_account_id_errors_when_missing_for_strategy_event exercises exactly this), or submissions routed to a client that failed to stamp the account.

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


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