nautechsystems/nautilus_trader · error · anyhow::Error

Invalid peg_price_type: {s}

Error message

Invalid peg_price_type: {s}

What it means

parse_peg_price_type reads the optional peg_price_type string from order command Params and converts it to a BitmexPegPriceType. If the parameter is present but is not a recognized peg price type enum value, it returns this error instead of silently dropping the peg instruction.

Source

Thrown at crates/adapters/bitmex/src/common/parse.rs:506

        is_reported,
        event_id,
        ts_event,
        ts_init,
        None,
    ))
}

/// Extracts the peg price type from order command parameters.
///
/// # Errors
///
/// Returns an error if the value is present but not a valid `BitmexPegPriceType`.
pub fn parse_peg_price_type(params: Option<&Params>) -> anyhow::Result<Option<BitmexPegPriceType>> {
    let value = params.and_then(|p| p.get_str("peg_price_type"));
    match value {
        Some(s) => BitmexPegPriceType::from_str(s)
            .map(Some)
            .map_err(|_| anyhow::anyhow!("Invalid peg_price_type: {s}")),
        None => Ok(None),
    }
}

/// Extracts the peg offset value from order command parameters.
///
/// # Errors
///
/// Returns an error if the value is present but not a valid `f64`.
pub fn parse_peg_offset_value(params: Option<&Params>) -> anyhow::Result<Option<f64>> {
    let value = params.and_then(|p| p.get_str("peg_offset_value"));
    match value {
        Some(s) => s
            .parse::<f64>()
            .map(Some)
            .map_err(|_| anyhow::anyhow!("Invalid peg_offset_value: {s}")),
        None => Ok(None),
    }

View on GitHub (pinned to 18893faf8b)

Solutions

  1. Use an exact valid BitMEX peg price type string (e.g. 'ParticipateDoNotInitiate', 'MarketPeg') in peg_price_type
  2. Check BitmexPegPriceType::from_str for the accepted values and match casing exactly
  3. Remove peg_price_type from Params if pegging is not intended

Example fix

// before
params.insert("peg_price_type", "MARKET_PEG");
// after
params.insert("peg_price_type", "MarketPeg");
Defensive patterns

Strategy: validation

Validate before calling

const VALID_PEG_TYPES: [&str; 6] = ["ParticipateDoNotInitiate", "MarketPeg", "PrimaryPeg", "MarkPrice", "LastPrice", "LastMidPrice"];
fn peg_type_ok(s: &str) -> bool { VALID_PEG_TYPES.contains(&s) }

Type guard

fn is_valid_peg(s: &str) -> bool { BitmexPegPriceType::from_str(s).is_ok() }

Try / catch

match client.submit_order(order) {
    Err(e) if e.to_string().starts_with("Invalid peg_price_type") => {
        log::error!("fix peg_price_type param: {e}");
        // correct the param and resubmit
    }
    r => r?,
}

Prevention

When it happens

Trigger: Submitting an order (submit_order or submit_order_list) with Params containing peg_price_type set to a string BitMEX adapter does not map (typo, wrong casing, unsupported peg type).

Common situations: Typos like 'MARKET' vs 'Market', passing Nautilus-native peg values not mapped to BitMEX's PegPriceType vocabulary, stale strategy code after adapter enum changes.

Understand the failure class

Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.

Related errors


AI-assisted analysis of nautechsystems/nautilus_trader@18893faf8b (2026-09-08). Data as JSON: /api/errors/4c52caf1c489cde4. Report an issue: GitHub.