nautechsystems/nautilus_trader · error

historical {field} {value} exceeds the maximum representable

Error message

historical {field} {value} exceeds the maximum representable price precision of {FIXED_PRECISION} decimals

What it means

After confirming the value is in (0, 1), validate_historical_price_evidence normalizes the Decimal and requires its scale (decimal places) to be <= FIXED_PRECISION, the adapter's fixed price precision. Historical evidence that needs more decimals cannot be represented exactly as a Polymarket fixed-precision price, so this anyhow error is raised.

Source

Thrown at crates/adapters/polymarket/src/execution/reconciliation.rs:313

        "{field} {value} must be greater than zero and less than one",
    );
    let price = Price::from_decimal_dp(value, precision).with_context(|| {
        format!("failed to represent {field} {value} with price precision {precision}")
    })?;
    anyhow::ensure!(
        price.as_decimal() == value,
        "{field} {value} is not exactly representable with price precision {precision}",
    );
    Ok(())
}

fn validate_historical_price_evidence(value: Decimal, field: &str) -> anyhow::Result<Price> {
    anyhow::ensure!(
        value > Decimal::ZERO && value < Decimal::ONE,
        "{field} {value} must be greater than zero and less than one",
    );
    let evidence = value.normalize();
    anyhow::ensure!(
        evidence.scale() <= u32::from(FIXED_PRECISION),
        "historical {field} {value} exceeds the maximum representable price precision of {FIXED_PRECISION} decimals",
    );
    let price = Price::from_decimal(evidence)
        .with_context(|| format!("failed to represent historical {field} {value}"))?;
    anyhow::ensure!(
        price.as_decimal() == value,
        "historical {field} {value} is not exactly representable as a price",
    );
    Ok(price)
}

#[derive(Clone, Copy, Debug)]
struct ValidatedOrderRow {
    venue_order_id: VenueOrderId,
    ts_accepted: UnixNanos,
    expire_time: Option<UnixNanos>,
}

View on GitHub (pinned to 18893faf8b)

Solutions

  1. Round or quantize the historical value to FIXED_PRECISION decimals before validation, accepting the rounding explicitly.
  2. Recompute the historical evidence from raw fills using exact tick-size multiples so it naturally fits the precision.
  3. If higher precision is genuinely needed, adjust FIXED_PRECISION in the adapter — only with awareness of the venue's tick constraints.

Example fix

// before
let avg = Decimal::new(5033333333, 10); // 0.5033333333 -> scale 10
validate_historical_price_evidence(avg, "avg_price")?;
// after
let avg = avg.round_dp(u32::from(FIXED_PRECISION));
validate_historical_price_evidence(avg, "avg_price")?;
Defensive patterns

Strategy: validation

Validate before calling

use rust_decimal::prelude::*;
fn fits_fixed_precision(v: rust_decimal::Decimal, dp: u32) -> bool {
    v.normalize().scale() <= dp
}
let value = avg.round_dp(u32::from(FIXED_PRECISION));

Type guard

fn is_representable(v: &rust_decimal::Decimal, fixed_precision: u32) -> bool {
    v.normalize().scale() <= fixed_precision
}

Try / catch

match validate_historical_price_evidence(value, field) {
    Err(e) if e.to_string().contains("exceeds the maximum representable price precision") => {
        let snapped = value.round_dp(u32::from(FIXED_PRECISION));
        validate_historical_price_evidence(snapped, field)?
    }
    r => r?,
}

Prevention

When it happens

Trigger: A historical price Decimal with more decimal places than FIXED_PRECISION (after normalize(), so trailing zeros do not help) is passed through validate_trade_values -> validate_historical_price_evidence, e.g. 0.1234567 with a 6-decimal FIXED_PRECISION.

Common situations: Aggregating or averaging fills produces long repeating decimals (e.g. average price 0.5033333333); importing prices from an exchange/export with higher tick precision; version change where FIXED_PRECISION was lowered.

Understand the failure class

Background: "value must be between 0 and 1" / "out of range" / "must not be negative" errors: fixing range-validation failures across open-source libraries — this error's family across 42 libraries.

Related errors


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