{"record":{"id":"530cc152e91b165e","repo":"nautechsystems/nautilus_trader","slug":"cannot-generate-operation-event-for-order-clien","errorCode":null,"errorMessage":"Cannot generate {operation} event for {order.client_order_id()}: account_id is not set","messagePattern":"Cannot generate (.+?) event for (.+?): account_id is not set","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/trading/src/strategy/mod.rs","lineNumber":2448,"sourceCode":"        log::info!(\"{id} {CMD}{SEND} {command}\");\n    } else {\n        log::info!(\"{CMD}{SEND} {command}\");\n    }\n}\n\nfn registered_trader_id(core: &StrategyCore) -> anyhow::Result<TraderId> {\n    core.trader_id()\n        .ok_or_else(|| anyhow::anyhow!(\"Strategy not registered: trader_id is not set\"))\n}\n\nfn registered_strategy_id(core: &StrategyCore) -> anyhow::Result<StrategyId> {\n    core.strategy_id()\n        .ok_or_else(|| anyhow::anyhow!(\"Strategy not registered: strategy_id is not set\"))\n}\n\nfn required_account_id(order: &OrderAny, operation: &str) -> anyhow::Result<AccountId> {\n    order.account_id().ok_or_else(|| {\n        anyhow::anyhow!(\n            \"Cannot generate {operation} event for {}: account_id is not set\",\n            order.client_order_id()\n        )\n    })\n}\n\n#[cfg(test)]\nmod tests {\n    use std::{cell::RefCell, rc::Rc};\n\n    use nautilus_common::{\n        actor::{\n            DataActor,\n            registry::{deregister_actor, try_get_actor_unchecked},\n        },\n        cache::{Cache, ORDER_NOT_FOUND},\n        clock::{Clock, TestClock},\n        component::{Component, deregister_component, register_component_actor},","sourceCodeStart":2430,"sourceCodeEnd":2466,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/trading/src/strategy/mod.rs#L2430-L2466","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Set account_id when constructing or importing orders (order.set_account_id / correct submission path).","Only route orders to mark_pending_* that were submitted through the strategy's execution client.","For external orders, wait for the reconciliation/event that attaches account_id before generating strategy events.","Fix test fixtures to include a valid AccountId."],"exampleFix":"// before\nlet order = OrderAny::new(TestOrderStub::default(), UUID4::new());\nstrategy.cancel_order(&order.client_order_id())?;\n// after\nlet mut order = OrderAny::new(TestOrderStub::default(), UUID4::new());\norder.set_account_id(account_id);\nstrategy.cancel_order(&order.client_order_id())?;","handlingStrategy":"validation","validationCode":"if order.account_id().is_none() {\n    return Err(format!(\"order {} has no account_id; cannot generate strategy event\", order.client_order_id()));\n}","typeGuard":null,"tryCatchPattern":"if let Err(e) = strategy.cancel_order(&order.client_order_id()) {\n    if e.to_string().contains(\"account_id is not set\") { log::warn!(\"skipping external order without account: {e}\"); }\n}","preventionTips":["Always set account_id when constructing or importing orders","Only route strategy-owned orders to mark_pending_* paths","Fix fixtures to include a valid AccountId"],"tags":["rust","order-management","account-id"],"backgroundTag":"empty-required-field","analyzedSha":"18893faf8b356be3320add8de2f861b0b647cf06","analyzedAt":"2026-09-08T20:49:34.690Z","contentChangedAt":"2026-09-08T20:49:34.690Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}