nautechsystems/nautilus_trader · error · OrderError

{e}

Error message

{e}

What it means

OrderFactory::market builds a market order via try_market and panics on any underlying validation error, propagating the error text as the panic message. Any condition that makes try_market return Err (e.g. invalid instrument state or price/quantity constraints) surfaces here as a panic.

Source

Thrown at crates/common/src/factories/order.rs:169

        quote_quantity: Option<bool>,
        exec_algorithm_id: Option<ExecAlgorithmId>,
        exec_algorithm_params: Option<IndexMap<Ustr, Ustr>>,
        tags: Option<Vec<Ustr>>,
        client_order_id: Option<ClientOrderId>,
    ) -> OrderAny {
        self.try_market(
            instrument_id,
            order_side,
            quantity,
            time_in_force,
            reduce_only,
            quote_quantity,
            exec_algorithm_id,
            exec_algorithm_params,
            tags,
            client_order_id,
        )
        .unwrap_or_else(|e| panic!("{e}"))
    }

    #[expect(clippy::too_many_arguments)]
    pub(crate) fn try_market(
        &mut self,
        instrument_id: InstrumentId,
        order_side: OrderSide,
        quantity: Quantity,
        time_in_force: Option<TimeInForce>,
        reduce_only: Option<bool>,
        quote_quantity: Option<bool>,
        exec_algorithm_id: Option<ExecAlgorithmId>,
        exec_algorithm_params: Option<IndexMap<Ustr, Ustr>>,
        tags: Option<Vec<Ustr>>,
        client_order_id: Option<ClientOrderId>,
    ) -> anyhow::Result<OrderAny> {
        let client_order_id = client_order_id.unwrap_or_else(|| self.generate_client_order_id());
        let exec_spawn_id: Option<ClientOrderId> = if exec_algorithm_id.is_none() {

View on GitHub (pinned to 18893faf8b)

Solutions

  1. Switch to try_market and handle the returned Result to see the real validation error
  2. Validate the instrument supports MARKET orders and that qty/price precisions are correct
  3. Verify instrument_id matches a registered instrument and client_order_id format
  4. Fix the fixture/config value reported in the propagated error message

Example fix

// before
let order = factory.market(instrument_id, OrderSide::Buy, Quantity::from(0));
// after
let order = factory.try_market(instrument_id, OrderSide::Buy, Quantity::from(1), None)?;
Defensive patterns

Strategy: try-catch

Validate before calling

// prefer fallible construction
let order = factory.try_market(instrument_id, side, qty, None)?;

Try / catch

// use the Result-returning variant instead of the panicking one
match factory.try_market(instrument_id, side, qty, None) {
    Ok(order) => { /* use order */ }
    Err(e) => eprintln!("market order rejected: {e}"),
}

Prevention

When it happens

Trigger: Calling market() with parameters that fail try_market validation — such as an instrument that doesn't allow market orders, invalid quantity/price precision, or a bad client_order_id — instead of using the fallible try_market API.

Common situations: Test helpers building orders with fixtures whose instrument_id doesn't match a registered instrument; migrating code to the panic variant to 'simplify' setup and hitting a validation rule; wrong tick size/precision in instrument definitions.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


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