nautechsystems/nautilus_trader · error

Last required

Error message

Last required

What it means

Raised by trailing_stop_calculate in crates/execution/src/trailing.rs when a trailing stop order uses TriggerType::LastOrBidAsk but no last traded price was supplied. In this mode the trigger price must be computed from the last price, so a None value makes the calculation impossible and the function fails fast with anyhow. It protects against silently computing a trigger from wrong data.

Source

Thrown at crates/execution/src/trailing.rs:155

                ask.ok_or_else(|| anyhow::anyhow!("Ask required"))?,
            );
            let basis = match order_side {
                OrderSide::Buy => ask,
                OrderSide::Sell => bid,
            };
            let cand_trigger = compute(trailing_offset, basis)?;
            new_trigger_price = maybe_move(&mut trigger_price, cand_trigger, better_trigger);

            if order_type == OrderType::TrailingStopLimit {
                let limit_offset = order.limit_offset().ok_or_else(|| {
                    anyhow::anyhow!("Missing `limit_offset` for trailing stop limit calculation")
                })?;
                let cand_limit = compute(limit_offset, basis)?;
                new_limit_price = maybe_move(&mut limit_price, cand_limit, better_limit);
            }

            if trigger_type == TriggerType::LastOrBidAsk {
                let last = last.ok_or_else(|| anyhow::anyhow!("Last required"))?;
                let cand_trigger = compute(trailing_offset, last)?;
                let updated = maybe_move(&mut trigger_price, cand_trigger, better_trigger);
                if updated.is_some() {
                    new_trigger_price = updated;
                }

                if order_type == OrderType::TrailingStopLimit {
                    let limit_offset = order.limit_offset().ok_or_else(|| {
                        anyhow::anyhow!(
                            "Missing `limit_offset` for trailing stop limit calculation"
                        )
                    })?;
                    let cand_limit = compute(limit_offset, last)?;
                    let updated = maybe_move(&mut limit_price, cand_limit, better_limit);
                    if updated.is_some() {
                        new_limit_price = updated;
                    }
                }

View on GitHub (pinned to 18893faf8b)

Solutions

  1. Supply the last traded price in the calculation inputs when trigger_type is LastOrBidAsk
  2. Switch the order's trigger type to a bid/ask-based trigger (e.g. BidOrLast/Crossing) if only quotes are available
  3. Guard the call site: fetch the latest trade tick and skip/error before calling if none exists
  4. Verify the data feed actually emits trade ticks for the instrument

Example fix

// before
let calc = trailing_stop_calculate(&order, bid, ask, None, ...)?;
// after
let last = last_trade_price.ok_or_else(|| anyhow::anyhow!("no last price for LastOrBidAsk trigger"))?;
let calc = trailing_stop_calculate(&order, bid, ask, Some(last), ...)?;
Defensive patterns

Strategy: validation

Validate before calling

if order.trigger_type() == TriggerType::LastOrBidAsk && last.is_none() {
    return Err(anyhow::anyhow!("LastOrBidAsk trigger requires a last traded price"));
}

Type guard

fn has_last_price(last: Option<Price>) -> bool { last.is_some() }

Prevention

When it happens

Trigger: Calling trailing_stop_calculate (directly or via update_trailing_stop_order) with order_type TrailingStop/TrailingStopLimit, trigger_type TriggerType::LastOrBidAsk, and last: None in the calculation inputs.

Common situations: Feeding market data that has no trade ticks (quote-only instruments), wiring only bid/ask into the calculator while the order expects last-price triggers, or leaving the last price field unset after a data gap at the start of a session.

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