{"record":{"id":"74094cd161db2483","repo":"nautechsystems/nautilus_trader","slug":"executionalgorithm-not-registered-trader-id-is-no","errorCode":null,"errorMessage":"ExecutionAlgorithm not registered: trader_id is not set","messagePattern":"ExecutionAlgorithm not registered: trader_id is not set","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/trading/src/algorithm/mod.rs","lineNumber":1536,"sourceCode":"    }\n}\n\nimpl std::error::Error for EmulatedOrderSubmissionError {}\n\nfn publish_order_initialized(order: &OrderAny) {\n    let event = OrderEventAny::Initialized(order.init_event().clone());\n    publish_order_event(&event);\n}\n\nfn publish_order_event(event: &OrderEventAny) {\n    let topic = format!(\"events.order.{}\", event.strategy_id());\n    msgbus::publish_order_event(topic.into(), event);\n}\n\nfn registered_trader_id(core: &ExecutionAlgorithmCore) -> anyhow::Result<TraderId> {\n    DataActorNative::core(core)\n        .trader_id()\n        .ok_or_else(|| anyhow::anyhow!(\"ExecutionAlgorithm not registered: trader_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::DataActor,\n        cache::Cache,","sourceCodeStart":1518,"sourceCodeEnd":1554,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/trading/src/algorithm/mod.rs#L1518-L1554","documentation":"Raised by `registered_trader_id` in the execution algorithm module when `ExecutionAlgorithmCore` has no `trader_id` set, meaning the algorithm is not (fully) registered with a running trader. Order-denying/submit/modify/cancel operations need the trader context to publish correctly attributed order events, so they fail with this error.","triggerScenarios":"Calling `deny_order`, `submit_order`, `modify_order`, or `cancel_order` on an `ExecutionAlgorithm` that was never initialized/registered by a trader — `DataActorNative::core(core).trader_id()` returns `None` because registration never set the trader context.","commonSituations":"Submitting an order to an algorithm before the system/trader has started; using an algorithm instance outside a configured trading system; ordering operations racing trader startup/shutdown; constructing the algorithm manually instead of via the system's registration path.","solutions":["Ensure the trader/system is started and the algorithm is registered before issuing submit/modify/cancel/deny calls","Wait for the system to reach its running/ready state (await start completion) before routing orders through the algorithm","Use the standard system builder/registration path so the algorithm receives its core context (trader_id) at initialization","Check shutdown ordering — do not submit orders to an algorithm whose trader is already disposed"],"exampleFix":"// before\nalgo.submit_order(order); // algo not yet registered\n// after\nsystem.start().await;\nassert!(system.is_running());\nalgo.submit_order(order);","handlingStrategy":"validation","validationCode":"// only route orders through a registered, running algorithm\nif !system.is_running() || !algo.is_registered() {\n    return Err(\"algorithm not registered with running trader\");\n}","typeGuard":"fn can_route(algo: &ExecutionAlgorithm, system: &System) -> bool {\n    algo.is_registered() && system.is_running()\n}","tryCatchPattern":"match algo.submit_order(order) {\n    Err(e) if e.to_string().contains(\"not registered: trader_id is not set\") => {\n        // await system.start() completion, then retry once\n    }\n    other => other?,\n}","preventionTips":["Always start the trading system before submitting orders through algorithms","Register algorithms via the system builder so trader context is set","Gate order routing on system running/ready state","Avoid sending orders during startup or shutdown windows"],"tags":["execution-algorithm","trader","lifecycle","orders"],"backgroundTag":"invalid-state-transition","analyzedSha":"18893faf8b356be3320add8de2f861b0b647cf06","analyzedAt":"2026-09-08T20:49:34.690Z","contentChangedAt":"2026-09-08T20:49:34.690Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}