{"record":{"id":"dcfc025e0f6fb0e8","repo":"nautechsystems/nautilus_trader","slug":"ordermessagebuilder-not-initialized-call-connect","errorCode":null,"errorMessage":"OrderMessageBuilder not initialized - call connect() first","messagePattern":"OrderMessageBuilder not initialized - call connect\\(\\) first","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/adapters/dydx/src/execution/mod.rs","lineNumber":844,"sourceCode":"        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:?}\");\n            }\n        };\n\n        self.spawn_labeled(label, future);\n    }\n","sourceCodeStart":826,"sourceCodeEnd":862,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/dydx/src/execution/mod.rs#L826-L862","documentation":"The OrderMessageBuilder converts Nautilus order objects into dYdX protobuf messages and, like the other components, is stored in an Option filled by connect(). If get_execution_components() finds it None when an order/cancel is submitted, this error is thrown. It means the client is being used in a partially or wholly uninitialized state.","triggerScenarios":"Calling submit_order, submit_order_list, cancel_order, cancel_all_orders, or batch_cancel_orders before connect() finished; this branch runs only when tx_manager and broadcaster are already set, so connect() failed after initializing them but before the order_builder.","commonSituations":"Transient failure during connect() leaving later components unset; submitting from a callback that fires before connection completes; reusing a client across a failed reconnect.","solutions":["Call and await connect() fully before trading operations","Check connect() error path/logs to find why initialization stopped at order_builder","Recreate the client (or call connect() again) so all three components are initialized"],"exampleFix":"// before\nlet client = DydxExecClient::new(config)?;\ntokio::spawn(async move { client.submit_order(order) }); // races connect()\n// after\nlet client = DydxExecClient::new(config)?;\nclient.connect().await?;\ntokio::spawn(async move { client.submit_order(order) });","handlingStrategy":"try-catch","validationCode":"if !client.is_connected() {\n    client.connect().await?;\n}","typeGuard":null,"tryCatchPattern":"match client.submit_order(order).await {\n    Err(e) if e.to_string().contains(\"not initialized - call connect()\") => {\n        client.connect().await?;\n        client.submit_order(order).await?;\n    }\n    r => r?,\n}","preventionTips":["Initialize the client in a single startup phase (new -> connect -> trade) and enforce that order in code review","Recreate the client instead of reusing one whose connect() failed","Add an integration test that asserts trading calls fail cleanly without connect() and succeed after it"],"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-14T05:17:10.506Z"}