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

Parameter validation in BitmexHttpClient.submit_order: a peg offset value was supplied in the order params without an accompanying peg_price_type. BitMEX cannot interpret a peg offset without knowing the peg price type, so the order is rejected before submission.

Source

Thrown at crates/adapters/bitmex/src/http/client.rs:1721

            {
                anyhow::bail!(
                    "BitMEX only supports PRICE trailing offset type, was {offset_type:?}"
                );
            }

            params.peg_price_type(BitmexPegPriceType::TrailingStopPeg);

            // BitMEX requires negative offset for stop-sell orders
            let signed_offset = match order_side {
                OrderSide::Sell => -offset.abs(),
                OrderSide::Buy => offset.abs(),
            };
            params.peg_offset_value(signed_offset);
        }

        // Pegged orders (BBO) via params override
        if peg_price_type.is_none() && peg_offset_value.is_some() {
            anyhow::bail!("`peg_offset_value` requires `peg_price_type`");
        }

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

            if let Some(offset) = peg_offset_value {
                params.peg_offset_value(offset);
            }
        }

        let mut exec_inst = Vec::new();

View on GitHub (pinned to 18893faf8b)

Solutions

  1. Supply peg_price_type (e.g. PrimaryPeg, LastPeg) together with peg_offset_value
  2. Drop peg_offset_value if no peg is intended
  3. Centralize order parameter construction so peg fields are set as a pair

Example fix

// before
params.peg_offset_value(offset); // no peg type
// after
params.peg_price_type(BitmexPegPriceType::PrimaryPeg).peg_offset_value(offset);
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 BitmexHttpClient::submit_order with peg_offset_value=Some(...) and peg_price_type=None.

Common situations: Building submit params manually and forgetting the peg price type; passing an offset for a trailing-stop path that already pegs internally but supplying the explicit peg_offset_value without an explicit peg_price_type.

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