nautechsystems/nautilus_trader · error · anyhow::Error

Actor {} has no trader ID

Error message

Actor {} has no trader ID

What it means

DataActor::reconnect_socket needs the actor's TraderId to build a ReconnectSocket command. `self.trader_id` is an Option that is only populated once the actor is registered with a Trader; if it is None the command cannot be addressed and the method returns this anyhow error.

Source

Thrown at crates/common/src/actor/data_actor.rs:5763

    ///
    /// Returns an error if the actor is not registered, the endpoint label is invalid, the live
    /// runner is unavailable, or the command channel is closed.
    #[cfg(feature = "live")]
    pub fn reconnect_socket(&self, client_id: ClientId, endpoint: &str) -> anyhow::Result<()> {
        let endpoint = socket_endpoint(endpoint)?;

        if !self.is_properly_registered() {
            anyhow::bail!(
                "Actor {} has not been registered with a Trader",
                self.actor_id
            );
        }

        let sender = try_get_system_command_sender()
            .ok_or_else(|| anyhow::anyhow!("Live runner system command channel is unavailable"))?;
        let trader_id = self
            .trader_id
            .ok_or_else(|| anyhow::anyhow!("Actor {} has no trader ID", self.actor_id))?;
        let command = ReconnectSocket::new(trader_id, client_id, endpoint, self.timestamp_ns());
        sender
            .send(SystemCommand::ReconnectSocket(command))
            .map_err(|_| anyhow::anyhow!("Live runner system command channel is closed"))?;
        Ok(())
    }

    #[cfg(test)]
    pub fn quote_handler_count(&self) -> usize {
        self.quote_handlers.len()
    }

    #[cfg(test)]
    pub fn trade_handler_count(&self) -> usize {
        self.trade_handlers.len()
    }

    #[cfg(test)]

View on GitHub (pinned to 18893faf8b)

Solutions

  1. Register the actor with a Trader before calling reconnect_socket (trader.register_actor / trader.add_actor) so trader_id is set.
  2. Verify registration succeeded — the method already logs a warning when the actor is not registered; fix the registration path that produced it.
  3. Defer reconnect_socket calls until after the actor's on_start lifecycle, when registration is guaranteed.
  4. In tests, set the actor's trader_id explicitly (or register with a test Trader) before exercising reconnect logic.

Example fix

// before
let actor = MyDataActor::new(config);
actor.reconnect_socket(client_id, endpoint)?; // trader_id is None

// after
let actor = MyDataActor::new(config);
trader.add_actor(actor.clone()); // populates trader_id
actor.reconnect_socket(client_id, endpoint)?;
Defensive patterns

Strategy: validation

Validate before calling

// Rust
if actor.trader_id.is_none() {
    anyhow::bail!("actor {} must be registered with a Trader before reconnect_socket", actor.actor_id);
}

Type guard

fn has_trader_id(actor: &DataActor) -> bool { actor.trader_id.is_some() }

Try / catch

if let Err(e) = actor.reconnect_socket(client_id, endpoint) {
    if e.to_string().contains("has no trader ID") {
        tracing::error!("actor not registered with a Trader: {e}");
    } else {
        return Err(e);
    }
}

Prevention

When it happens

Trigger: Calling reconnect_socket on a DataActor whose trader_id is None — i.e. the actor was never registered with a Trader (no register_with_trader / Trader registration) before the reconnect request was made.

Common situations: Instantiating a DataActor and calling socket-reconnect logic directly without adding it to a Trader; wiring actors manually instead of through the node builder; lifecycle races where reconnect is requested during actor startup before registration completes.

Understand the failure class

Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.

Related errors


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