nautechsystems/nautilus_trader · error

TxBroadcaster not initialized - call connect() first

Error message

TxBroadcaster not initialized - call connect() first

What it means

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.

Solutions

  1. Await connect() to completion before any trading calls
  2. Investigate why connect() stopped between initializing tx_manager and broadcaster (check RPC endpoint health, logs)
  3. Reconnect or recreate the client to re-run full component initialization

Example fix

// before
client.connect().await; // not awaited/checked
client.cancel_all_orders(instrument_id)?;
// after
client.connect().await?; // propagate failure
client.cancel_all_orders(instrument_id)?;
Defensive patterns

Strategy: try-catch

Validate before calling

if !client.is_connected() {
    client.connect().await?;
}

Try / catch

if let Err(e) = client.cancel_all_orders(instrument_id).await {
    if e.to_string().contains("TxBroadcaster not initialized") {
        client.connect().await?;
        // retry cancel after reconnection
    }
}

Prevention

When it happens

Trigger: 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).

Common situations: 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.

Understand the failure class

Background: "Invalid state transition" errors: "status must be X, actually Y", "already rejected/charging/uninstalled", "cannot ... while running" — what they mean when a library rejects your call — this error's family across 31 libraries.

Related errors


AI-assisted analysis of nautechsystems/nautilus_trader@18893faf8b (2026-09-08). Data as JSON: /api/errors/f2ef3990b9f26567. Report an issue: GitHub.

Appendix: source

Thrown at crates/adapters/dydx/src/execution/mod.rs:838

    fn get_execution_components(
        &self,
    ) -> anyhow::Result<(
        Arc<TransactionManager>,
        Arc<TxBroadcaster>,
        Arc<OrderMessageBuilder>,
    )> {
        let tx_manager = self
            .tx_manager
            .as_ref()
            .ok_or_else(|| {
                anyhow::anyhow!("TransactionManager not initialized - call connect() first")
            })?
            .clone();
        let broadcaster = self
            .broadcaster
            .as_ref()
            .ok_or_else(|| anyhow::anyhow!("TxBroadcaster not initialized - call connect() first"))?
            .clone();
        let order_builder = self
            .order_builder
            .as_ref()
            .ok_or_else(|| {
                anyhow::anyhow!("OrderMessageBuilder not initialized - call connect() first")
            })?
            .clone();
        Ok((tx_manager, broadcaster, order_builder))
    }

    fn spawn_task<F>(&self, label: &'static str, fut: F)
    where
        F: Future<Output = anyhow::Result<()>> + Send + 'static,
    {
        let future = async move {
            if let Err(e) = fut.await {
                log::error!("{label}: {e:?}");

View on GitHub (pinned to 18893faf8b)