nautechsystems/nautilus_trader · error · anyhow::Error

`peg_offset_value` requires `peg_price_type`

Error message

`peg_offset_value` requires `peg_price_type`

What it means

BitMEX order validation rejects a submit that supplies `peg_offset_value` without also specifying `peg_price_type`. BitMEX pegged orders are defined by a peg reference price type; an offset alone is meaningless to the venue. validate_order_for_bitmex_submit bails early so the malformed order is never sent.

Source

Thrown at crates/adapters/bitmex/src/execution.rs:1310

    peg_offset_value: Option<f64>,
) -> anyhow::Result<()> {
    BitmexOrderType::try_from_order_type(order.order_type())?;
    BitmexTimeInForce::try_from_time_in_force(order.time_in_force())?;

    let is_trailing_stop = matches!(
        order.order_type(),
        OrderType::TrailingStopMarket | OrderType::TrailingStopLimit
    );

    if is_trailing_stop
        && let Some(offset_type) = order.trailing_offset_type()
        && offset_type != TrailingOffsetType::Price
    {
        anyhow::bail!("BitMEX only supports PRICE trailing offset type, was {offset_type:?}");
    }

    if peg_price_type.is_none() && peg_offset_value.is_some() {
        anyhow::bail!("`peg_offset_value` requires `peg_price_type`");
    }

    if peg_price_type.is_some() && order.order_type() != OrderType::Limit {
        let order_type = order.order_type();
        anyhow::bail!("Pegged orders only supported for LIMIT order type, was {order_type:?}");
    }

    if let Some(contingency_type) = order.contingency_type() {
        BitmexContingencyType::try_from(contingency_type)?;
    }

    Ok(())
}

fn is_definitive_bitmex_submit_rejection(err: &anyhow::Error) -> bool {
    if is_bitmex_duplicate_clordid_submit_failure(err) {
        return false;
    }

View on GitHub (pinned to 18893faf8b)

Solutions

  1. Set peg_price_type (e.g. BitmexPegPriceType::PrimaryPeg or TrailingStopPeg) whenever peg_offset_value is provided
  2. If no peg is intended, clear peg_offset_value as well
  3. Check the order factory/config so both peg fields are populated together

Example fix

// before
.with_peg_offset_value(Decimal::from(1))
// after
.with_peg_price_type(BitmexPegPriceType::PrimaryPeg)
.with_peg_offset_value(Decimal::from(1))
Defensive patterns

Strategy: validation

Validate before calling

if peg_offset_value.is_some() && peg_price_type.is_none() {
    return Err(anyhow::anyhow!("peg_offset_value requires peg_price_type"));
}

Prevention

When it happens

Trigger: Calling validate_order_for_bitmex_submit (directly or via submit_cached_order) with Some(peg_offset_value) but peg_price_type=None.

Common situations: Strategy code sets only a peg offset for a pegged-to-BBO limit order and forgets the peg type; refactoring drops the peg_price_type field from order parameters.

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