nautechsystems/nautilus_trader · error

Limit offset not set

Error message

Limit offset not set

What it means

OrderTestBuilder::get_limit_offset unwraps Option<Decimal> set via .limit_offset(...). build() for trailing order types that require a limit offset panics with 'Limit offset not set' when it was never provided.

Source

Thrown at crates/model/src/orders/builder.rs:236

    // ----------- TriggerType ----------
    pub fn trigger_type(&mut self, trigger_type: TriggerType) -> &mut Self {
        self.trigger_type = Some(trigger_type);
        self
    }

    fn get_trigger_type(&self) -> TriggerType {
        self.trigger_type.unwrap_or(TriggerType::Default)
    }

    // ----------- LimitOffset ----------
    pub fn limit_offset(&mut self, limit_offset: Decimal) -> &mut Self {
        self.limit_offset = Some(limit_offset);
        self
    }

    fn get_limit_offset(&self) -> Decimal {
        self.limit_offset.expect("Limit offset not set")
    }

    // ----------- TrailingOffset ----------
    pub fn trailing_offset(&mut self, trailing_offset: Decimal) -> &mut Self {
        self.trailing_offset = Some(trailing_offset);
        self
    }

    fn get_trailing_offset(&self) -> Decimal {
        self.trailing_offset.expect("Trailing offset not set")
    }

    // ----------- TrailingOffsetType ----------
    pub fn trailing_offset_type(&mut self, trailing_offset_type: TrailingOffsetType) -> &mut Self {
        self.trailing_offset_type = Some(trailing_offset_type);
        self
    }

View on GitHub (pinned to 18893faf8b)

Solutions

  1. Add .limit_offset(Decimal::from(...)) to the builder chain before build().
  2. Set both limit_offset and trailing_offset together for trailing stop-limit orders.
  3. Use a trailing-order fixture that supplies both offsets.

Example fix

// before
let order = OrderTestBuilder::new(OrderType::TrailingStopLimit)
    .trailing_offset(Decimal::from(100))
    .build();
// after
let order = OrderTestBuilder::new(OrderType::TrailingStopLimit)
    .trailing_offset(Decimal::from(100))
    .limit_offset(Decimal::from(50))
    .build();
Defensive patterns

Strategy: validation

Validate before calling

if matches!(order_type, OrderType::TrailingStopLimit) {
    assert!(limit_offset.is_some(), "limit_offset required for TrailingStopLimit");
}
builder.limit_offset(limit_offset.unwrap()).build();

Try / catch

// assert before build
assert!(limit_offset.is_some());

Prevention

When it happens

Trigger: Building a TrailingStopLimit (or other offset-requiring order) via OrderTestBuilder without chaining .limit_offset(Decimal) before build().

Common situations: Testing trailing stop-limit orders while setting only the trailing offset and forgetting that the limit offset is a separate required field.

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/b43a70476e54e4bf. Report an issue: GitHub.