nautechsystems/nautilus_trader · error

Trader cannot register with itself

Error message

Trader cannot register with itself

What it means

Trader's Component register trait method is intentionally unimplemented for Trader itself — a trader cannot be registered as a component within itself. The registration call is rejected unconditionally with this bail.

Source

Thrown at crates/system/src/trader.rs:1792

    }

    fn state(&self) -> ComponentState {
        self.state
    }

    fn transition_state(&mut self, trigger: ComponentTrigger) -> anyhow::Result<()> {
        self.state = self.state.transition(&trigger)?;
        log::info!("{}", self.state.variant_name());
        Ok(())
    }

    fn register(
        &mut self,
        _trader_id: TraderId,
        _clock: Rc<RefCell<dyn Clock>>,
        _cache: Rc<RefCell<Cache>>,
    ) -> anyhow::Result<()> {
        anyhow::bail!("Trader cannot register with itself")
    }

    fn on_start(&mut self) -> anyhow::Result<()> {
        Self::on_start(self)
    }

    fn on_stop(&mut self) -> anyhow::Result<()> {
        Self::on_stop(self)
    }

    fn on_reset(&mut self) -> anyhow::Result<()> {
        Self::on_reset(self)
    }

    fn on_dispose(&mut self) -> anyhow::Result<()> {
        Self::on_dispose(self)
    }
}

View on GitHub (pinned to 18893faf8b)

Solutions

  1. Exclude the Trader itself from generic component registration loops
  2. Register only strategies, actors, and exec algorithms with the trader, not trader instances
  3. If generic code calls register, filter by type: skip components that are Traders

Example fix

// before
for component in components {
    component.register(trader_id, clock.clone(), cache.clone())?;
}
// after
for component in components {
    if component.id() != self.trader_id().into() {
        component.register(trader_id, clock.clone(), cache.clone())?;
    }
}
Defensive patterns

Strategy: type-guard

Validate before calling

assert!(component.id() != trader.id());

Type guard

fn is_trader(c: &dyn Component) -> bool { c.as_any().is::<Trader>() }

Prevention

When it happens

Trigger: Calling register(trader_id, clock, cache) on a Trader instance, e.g. generic code that registers all components including the trader, or passing the trader as a strategy/actor to another trader.

Common situations: Generic component-registration loops that don't exclude the trader; mistakenly adding a Trader to another Trader's component list; refactored initialization code that treats Trader like any Actor.

Understand the failure class

Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.

Related errors


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