nautechsystems/nautilus_trader · error
Failed to parse '{field_name}' value '{value}' into Price: {
Error message
Failed to parse '{field_name}' value '{value}' into Price: {e} What it means
Second failure point in `parse_price`: the string parsed into a `Decimal` but converting the normalized decimal into a Nautilus `Price` via `Price::from_decimal_dp` failed. This happens when the value, though a valid decimal, cannot be represented as a Price (e.g. magnitude/precision outside Price's representable range).
Source
Thrown at crates/adapters/dydx/src/common/parse.rs:125
}
/// Parses a decimal string into a [`Price`].
///
/// Normalizes the decimal to strip trailing zeros and clamps precision to
/// [`FIXED_PRECISION`] to prevent panics from venue values with excessive
/// decimal places.
///
/// # Errors
///
/// Returns an error if the string cannot be parsed into a valid price.
pub fn parse_price(value: &str, field_name: &str) -> anyhow::Result<Price> {
let decimal = Decimal::from_str(value).map_err(|e| {
anyhow::anyhow!("Failed to parse '{field_name}' value '{value}' into Decimal: {e}")
})?;
let normalized = decimal.normalize();
let precision = (normalized.scale() as u8).min(FIXED_PRECISION);
Price::from_decimal_dp(normalized, precision).map_err(|e| {
anyhow::anyhow!("Failed to parse '{field_name}' value '{value}' into Price: {e}")
})
}
/// Parses a decimal string into a [`Quantity`].
///
/// Normalizes the decimal to strip trailing zeros and clamps precision to
/// [`FIXED_PRECISION`] to prevent panics from venue values with excessive
/// decimal places.
///
/// # Errors
///
/// Returns an error if the string cannot be parsed into a valid quantity.
pub fn parse_quantity(value: &str, field_name: &str) -> anyhow::Result<Quantity> {
let decimal = Decimal::from_str(value).map_err(|e| {
anyhow::anyhow!("Failed to parse '{field_name}' value '{value}' into Decimal: {e}")
})?;
let normalized = decimal.normalize();
let precision = (normalized.scale() as u8).min(FIXED_PRECISION);View on GitHub (pinned to 18893faf8b)
Solutions
- Confirm the price value is in the expected units and within a sane market magnitude
- Round the input to the instrument's price precision/step before parsing
- Inspect the wrapped `{e}` from Price::from_decimal_dp for the exact range violation
- Use parse_decimal first to inspect the raw value when debugging
Example fix
// before let price = parse_price(&wei_amount, "price")?; // 50000000000000000000 // after let human = Decimal::from_str(&wei_amount)? / Decimal::from(10u64.pow(18)); let price = parse_price(&human.to_string(), "price")?;
Defensive patterns
Strategy: validation
Validate before calling
// Bound-check magnitude before Price conversion
fn plausible_price(d: rust_decimal::Decimal) -> bool {
d > rust_decimal::Decimal::ZERO && d < rust_decimal::Decimal::from(1_000_000u64)
} Type guard
fn as_price(s: &str) -> Option<Price> { parse_price(s, "price").ok() } Try / catch
let price = parse_price(raw, "price").inspect_err(|e| log::error!("Price conversion failed: {e}"))?; Prevention
- Convert raw/token units to human units before parsing prices
- Clamp inputs to the instrument's price precision and range
- Sanity-check prices against market data before submission
When it happens
Trigger: Calling `parse_price` with a value whose precision or magnitude exceeds what `Price::from_decimal_dp` accepts after normalization and clamping to FIXED_PRECISION — e.g. astronomically large or sub-denominator-precision values.
Common situations: Prices pasted with many decimal places, values in wrong units (wei-style integers), or test/config values far outside sane market ranges.
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.
- Parsing and encoding errors: unexpected token, malformed input — why parsers reject input and how to find the real culprit.
Related errors
- Failed to parse '{field_name}' value '{value}' into Decimal:
- Failed to parse '{field_name}' value '{value}' into Quantity
- price precision {precision} exceeds maximum {MAX_DECIMALS}
- invalid price `{value}` at precision {precision}: {e}
- quantity size={} cannot be represented with precision={}
AI-assisted analysis of nautechsystems/nautilus_trader@18893faf8b (2026-09-08).
Data as JSON: /api/errors/be7a4a086e2a1225.
Report an issue: GitHub.