nautechsystems/nautilus_trader · error · anyhow::Error

trigger_price required for {order_type:?}

Error message

trigger_price required for {order_type:?}

What it means

dYdX conditional order types (STOP_LIMIT, STOP_MARKET, TAKE_PROFIT, TAKE_PROFIT_MARKET) require a trigger price that the validator checks against the limit price and side. validate_conditional_order throws this when a conditional order is submitted without a trigger_price parameter. It is a fail-fast guard before the order reaches the exchange.

Source

Thrown at crates/adapters/dydx/src/http/parse.rs:242

/// based on order type and side.
///
/// # Errors
///
/// Returns an error if:
/// - Conditional order is missing trigger price.
/// - Trigger price is on wrong side of limit price for the order type.
pub fn validate_conditional_order(
    order_type: DydxOrderType,
    trigger_price: Option<Decimal>,
    price: Decimal,
    side: OrderSide,
) -> anyhow::Result<()> {
    if !order_type.is_conditional() {
        return Ok(());
    }

    let trigger_price = trigger_price
        .ok_or_else(|| anyhow::anyhow!("trigger_price required for {order_type:?}"))?;

    // Validate trigger price relative to limit price
    match order_type {
        DydxOrderType::StopLimit | DydxOrderType::StopMarket => {
            // Stop orders: trigger when price falls (sell) or rises (buy)
            match side {
                OrderSide::Buy if trigger_price < price => {
                    anyhow::bail!(
                        "Stop buy trigger_price ({trigger_price}) must be >= limit price ({price})"
                    );
                }
                OrderSide::Sell if trigger_price > price => {
                    anyhow::bail!(
                        "Stop sell trigger_price ({trigger_price}) must be <= limit price ({price})"
                    );
                }
                _ => {}
            }

View on GitHub (pinned to 18893faf8b)

Solutions

  1. Provide the trigger_price argument when submitting any stop or take-profit (conditional) order type
  2. Check order_type first: only conditional types need trigger_price; non-conditional types return Ok early
  3. Use a validation helper or builder that makes trigger_price required for conditional order constructors
  4. Add a unit test mirroring test_validate_stop_limit_buy_invalid to catch missing trigger_price

Example fix

// before
submit_order(OrderType::StopMarket, side, quantity, price, None /* trigger_price */);
// after
submit_order(OrderType::StopMarket, side, quantity, price, Some(trigger_price));
Defensive patterns

Strategy: validation

Validate before calling

if order_type.is_conditional() && trigger_price.is_none() {
    return Err(anyhow!("trigger_price required for {order_type:?}"));
}
validate_conditional_order(order_type, side, trigger_price, limit_price)?;

Type guard

fn conditional_ready(t: DydxOrderType, tp: Option<Price>) -> bool {
    !t.is_conditional() || tp.is_some()
}

Try / catch

match validate_conditional_order(...) {
    Err(e) if e.to_string().contains("trigger_price required") => {
        eprintln!("Supply trigger_price for {order_type:?}");
    }
    Err(e) => return Err(e),
    Ok(()) => submit(),
}

Prevention

When it happens

Trigger: Calling validate_conditional_order (or placing an order through it) with order_type.is_conditional() true but the trigger_price Option set to None.

Common situations: Submitting a stop or take-profit order while omitting the trigger_price field; code paths that build conditional orders conditionally and skip trigger price on some branches; porting market/limit order code to conditional types without adding trigger price.

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