{"record":{"id":"f2ef3990b9f26567","repo":"nautechsystems/nautilus_trader","slug":"txbroadcaster-not-initialized-call-connect-fir","errorCode":null,"errorMessage":"TxBroadcaster not initialized - call connect() first","messagePattern":"TxBroadcaster not initialized - call connect\\(\\) first","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/adapters/dydx/src/execution/mod.rs","lineNumber":838,"sourceCode":"\n    fn get_execution_components(\n        &self,\n    ) -> anyhow::Result<(\n        Arc<TransactionManager>,\n        Arc<TxBroadcaster>,\n        Arc<OrderMessageBuilder>,\n    )> {\n        let tx_manager = self\n            .tx_manager\n            .as_ref()\n            .ok_or_else(|| {\n                anyhow::anyhow!(\"TransactionManager not initialized - call connect() first\")\n            })?\n            .clone();\n        let broadcaster = self\n            .broadcaster\n            .as_ref()\n            .ok_or_else(|| anyhow::anyhow!(\"TxBroadcaster not initialized - call connect() first\"))?\n            .clone();\n        let order_builder = self\n            .order_builder\n            .as_ref()\n            .ok_or_else(|| {\n                anyhow::anyhow!(\"OrderMessageBuilder not initialized - call connect() first\")\n            })?\n            .clone();\n        Ok((tx_manager, broadcaster, order_builder))\n    }\n\n    fn spawn_task<F>(&self, label: &'static str, fut: F)\n    where\n        F: Future<Output = anyhow::Result<()>> + Send + 'static,\n    {\n        let future = async move {\n            if let Err(e) = fut.await {\n                log::error!(\"{label}: {e:?}\");","sourceCodeStart":820,"sourceCodeEnd":856,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/dydx/src/execution/mod.rs#L820-L856","documentation":"Like the TransactionManager, the TxBroadcaster (which submits signed transactions to dYdX) is stored in an Option populated by connect(). get_execution_components() requires it before any order/cancel call; if it is None the client throws this error. It indicates the client was used before connection established all its components.","triggerScenarios":"submit_order, submit_order_list, cancel_order, cancel_all_orders, or batch_cancel_orders invoked before connect() succeeded; note that this error only appears once tx_manager was already initialized, so connect() failed partway through component setup (between tx_manager and broadcaster assignment).","commonSituations":"connect() raced with a submit call from another thread/task; connect() partially failed (tx_manager set, broadcaster not) due to an RPC or websocket error; missing await on connect before trading.","solutions":["Await connect() to completion before any trading calls","Investigate why connect() stopped between initializing tx_manager and broadcaster (check RPC endpoint health, logs)","Reconnect or recreate the client to re-run full component initialization"],"exampleFix":"// before\nclient.connect().await; // not awaited/checked\nclient.cancel_all_orders(instrument_id)?;\n// after\nclient.connect().await?; // propagate failure\nclient.cancel_all_orders(instrument_id)?;","handlingStrategy":"try-catch","validationCode":"if !client.is_connected() {\n    client.connect().await?;\n}","typeGuard":null,"tryCatchPattern":"if let Err(e) = client.cancel_all_orders(instrument_id).await {\n    if e.to_string().contains(\"TxBroadcaster not initialized\") {\n        client.connect().await?;\n        // retry cancel after reconnection\n    }\n}","preventionTips":["Gate all trading calls behind a successful, awaited connect()","Avoid fire-and-forget tasks that may run before connection completes","Monitor connect() partial failures (RPC/websocket health) so components never end up half-initialized"],"tags":["rust","lifecycle","dydx","not-initialized"],"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-14T00:17:10.932Z"}