nautechsystems/nautilus_trader · error

failed to parse `{CONTINUOUS_FUTURE_ADJUSTMENT_MODE}`

Error message

failed to parse `{CONTINUOUS_FUTURE_ADJUSTMENT_MODE}`

What it means

The `adjustment_mode` parameter for a continuous future request must be an integer 1-4 mapping to BackwardSpread(1), ForwardSpread(2), BackwardRatio(3), or ForwardRatio(4). Any other value (including 0, values >4, or non-integer) is rejected.

Source

Thrown at crates/data/src/engine/requests.rs:490

    Ok(bar_types)
}

fn parse_adjustment_mode(value: Option<&Value>) -> anyhow::Result<ContinuousFutureAdjustmentType> {
    let Some(value) = value else {
        return Ok(ContinuousFutureAdjustmentType::default());
    };

    if let Some(raw) = value.as_str() {
        return ContinuousFutureAdjustmentType::from_str(raw)
            .with_context(|| format!("failed to parse `{CONTINUOUS_FUTURE_ADJUSTMENT_MODE}`"));
    }

    match value.as_u64() {
        Some(1) => Ok(ContinuousFutureAdjustmentType::BackwardSpread),
        Some(2) => Ok(ContinuousFutureAdjustmentType::ForwardSpread),
        Some(3) => Ok(ContinuousFutureAdjustmentType::BackwardRatio),
        Some(4) => Ok(ContinuousFutureAdjustmentType::ForwardRatio),
        _ => anyhow::bail!("failed to parse `{CONTINUOUS_FUTURE_ADJUSTMENT_MODE}`"),
    }
}

fn parse_optional_chain_bound(
    params: &Params,
    key: &str,
    target_instrument_id: InstrumentId,
) -> anyhow::Result<Option<InstrumentId>> {
    let Some(raw) = params.get_str(key) else {
        return Ok(None);
    };

    let instrument_id = InstrumentId::from_str(raw)
        .with_context(|| format!("Invalid continuous future {key} for {target_instrument_id}"))?;
    if instrument_id.venue != target_instrument_id.venue {
        anyhow::bail!(
            "Continuous future {key} venue mismatch for {target_instrument_id}: target venue {}, {key} venue {}",
            target_instrument_id.venue,

View on GitHub (pinned to 18893faf8b)

Solutions

  1. Send the numeric code: 1=BackwardSpread, 2=ForwardSpread, 3=BackwardRatio, 4=ForwardRatio.
  2. If sending a string, map it to the numeric enum before building the request params.
  3. Verify the value is a JSON integer, not a string or float.

Example fix

// before
json!({"adjustment_mode": "backward_spread"})
// after
json!({"adjustment_mode": 1}) // BackwardSpread
Defensive patterns

Strategy: validation

Validate before calling

assert!((1..=4).contains(&adjustment_mode), "adjustment_mode must be 1-4");

Type guard

fn is_valid_adjustment_mode(v: u64) -> bool { (1..=4).contains(&v) }

Prevention

When it happens

Trigger: parse_adjustment_mode receives a JSON value for `adjustment_mode` whose as_u64() is not 1, 2, 3, or 4 — e.g. 0, 5, a negative number, a string, or a float.

Common situations: Using 0-based enum indexing in client code (0 instead of 1-4); sending the mode name ("backward_spread") as a string instead of the numeric code; copying an adjustment-mode constant from another API with different numbering.

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