{"record":{"id":"7a052b4be7033285","repo":"nautechsystems/nautilus_trader","slug":"cannot-subscribe-continuous-future-bars-for-targe","errorCode":null,"errorMessage":"Cannot subscribe continuous future bars for {target_bar_type}: roller is not initialized; ensure `register_msgbus_handlers` runs before subscribing","messagePattern":"Cannot subscribe continuous future bars for (.+?): roller is not initialized; ensure `register_msgbus_handlers` runs before subscribing","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/data/src/engine/mod.rs","lineNumber":5178,"sourceCode":"                }\n            }\n        }\n\n        Ok(())\n    }\n\n    fn subscribe_continuous_future_bars(&mut self, cmd: &SubscribeBars) -> anyhow::Result<()> {\n        let target_bar_type = cmd.bar_type;\n        let target_key = target_bar_type.standard();\n\n        if !target_bar_type.is_internally_aggregated() {\n            anyhow::bail!(\n                \"Continuous future bar subscriptions require an internally aggregated target, was {target_bar_type}\"\n            );\n        }\n\n        if self.continuous_future_roller.is_none() {\n            anyhow::bail!(\n                \"Cannot subscribe continuous future bars for {target_bar_type}: roller is not initialized; ensure `register_msgbus_handlers` runs before subscribing\"\n            );\n        }\n\n        let request = continuous_future_subscription_from_bars(cmd)?.ok_or_else(|| {\n            anyhow::anyhow!(\n                \"Continuous future bar subscription requires `continuous_future_transitions`, was {cmd:?}\"\n            )\n        })?;\n\n        self.ensure_continuous_future_target_instrument(&request);\n\n        if self\n            .continuous_future_subscriptions\n            .contains_key(&target_key)\n        {\n            log::warn!(\"Continuous future bars already subscribed for {target_bar_type}\");\n            return Ok(());","sourceCodeStart":5160,"sourceCodeEnd":5196,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/data/src/engine/mod.rs#L5160-L5196","documentation":"The continuous future roller component must be registered (during register_msgbus_handlers) before continuous future bars can be subscribed. When subscribe_continuous_future_bars runs and engine.continuous_future_roller is None, the engine cannot stitch contract segments, so it fails with this initialization-order error.","triggerScenarios":"Subscribing to continuous future bars on a DataEngine whose register_msgbus_handlers() has not been called yet (or was not called at all), e.g. an engine constructed manually in a test or custom setup.","commonSituations":"Hand-constructed DataEngine in unit tests or custom nodes skipping register_msgbus_handlers; calling subscribe before the node finishes initialization; a custom builder that wires msgbus handlers later than subscriptions.","solutions":["Ensure register_msgbus_handlers() is called on the DataEngine before any subscribe_continuous_future_bars call.","If using a trader/node, only subscribe from strategy.on_start or later, after the node is fully initialized.","In tests, replicate the production init sequence: construct engine then call register_msgbus_handlers before subscriptions."],"exampleFix":"// before\nlet mut engine = DataEngine::new(...);\nengine.subscribe_continuous_future_bars(&cmd)?; // roller is None\n// after\nlet mut engine = DataEngine::new(...);\nengine.register_msgbus_handlers();\nengine.subscribe_continuous_future_bars(&cmd)?;","handlingStrategy":"validation","validationCode":"if engine.continuous_future_roller.is_none() {\n    engine.register_msgbus_handlers();\n}","typeGuard":null,"tryCatchPattern":"if let Err(e) = engine.subscribe_continuous_future_bars(&cmd) {\n    if e.to_string().contains(\"roller is not initialized\") {\n        engine.register_msgbus_handlers();\n        engine.subscribe_continuous_future_bars(&cmd)?;\n    } else { return Err(e); }\n}","preventionTips":["Always call register_msgbus_handlers immediately after constructing a DataEngine","Subscribe only from strategy.on_start, never during engine construction","Mirror the node/trader init sequence in custom harnesses and tests"],"tags":["rust","data-engine","initialization-order","futures"],"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"}