nautechsystems/nautilus_trader · error

Cannot update instrument {} with {}

Error message

Cannot update instrument {} with {}

What it means

Guard in OrderMatchingEngine::update_instrument: the new instrument definition's ID differs from the ID this matching engine was created for, so swapping the definition would corrupt the engine's book state and the update is refused.

Source

Thrown at crates/execution/src/matching_engine/mod.rs:1239

    }

    #[must_use]
    pub const fn get_core(&self) -> &OrderMatchingCore {
        &self.core
    }

    pub fn set_fill_at_market(&mut self, value: bool) {
        self.fill_at_market = value;
    }

    /// Updates the instrument definition used by this matching engine.
    ///
    /// # Errors
    ///
    /// Returns an error if `instrument.id()` does not match this engines instrument ID.
    pub fn update_instrument(&mut self, instrument: InstrumentAny) -> anyhow::Result<()> {
        if instrument.id() != self.instrument.id() {
            anyhow::bail!(
                "Cannot update instrument {} with {}",
                self.instrument.id(),
                instrument.id()
            );
        }

        let changed = instrument.price_increment() != self.instrument.price_increment()
            || instrument.price_precision() != self.instrument.price_precision()
            || instrument.size_precision() != self.instrument.size_precision();

        if changed {
            self.core
                .update_price_increment(instrument.price_increment());
            self.book.reset();
            self.trade_consumption = 0;
            self.bid_consumption.clear();
            self.ask_consumption.clear();
            self.queue_pending.clear();

View on GitHub (pinned to 18893faf8b)

Solutions

  1. Route the instrument to a matching engine created for that instrument ID
  2. Create a new matching engine for the new instrument instead of updating an existing one
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at crates/execution/src/matching_engine/mod.rs:1239 when the library encounters an invalid state.

Common situations: See trigger scenarios.


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