{"record":{"id":"be7a4a086e2a1225","repo":"nautechsystems/nautilus_trader","slug":"failed-to-parse-field-name-value-value-int-be7a4a","errorCode":null,"errorMessage":"Failed to parse '{field_name}' value '{value}' into Price: {e}","messagePattern":"Failed to parse '(.+?)' value '(.+?)' into Price: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/adapters/dydx/src/common/parse.rs","lineNumber":125,"sourceCode":"}\n\n/// Parses a decimal string into a [`Price`].\n///\n/// Normalizes the decimal to strip trailing zeros and clamps precision to\n/// [`FIXED_PRECISION`] to prevent panics from venue values with excessive\n/// decimal places.\n///\n/// # Errors\n///\n/// Returns an error if the string cannot be parsed into a valid price.\npub fn parse_price(value: &str, field_name: &str) -> anyhow::Result<Price> {\n    let decimal = Decimal::from_str(value).map_err(|e| {\n        anyhow::anyhow!(\"Failed to parse '{field_name}' value '{value}' into Decimal: {e}\")\n    })?;\n    let normalized = decimal.normalize();\n    let precision = (normalized.scale() as u8).min(FIXED_PRECISION);\n    Price::from_decimal_dp(normalized, precision).map_err(|e| {\n        anyhow::anyhow!(\"Failed to parse '{field_name}' value '{value}' into Price: {e}\")\n    })\n}\n\n/// Parses a decimal string into a [`Quantity`].\n///\n/// Normalizes the decimal to strip trailing zeros and clamps precision to\n/// [`FIXED_PRECISION`] to prevent panics from venue values with excessive\n/// decimal places.\n///\n/// # Errors\n///\n/// Returns an error if the string cannot be parsed into a valid quantity.\npub fn parse_quantity(value: &str, field_name: &str) -> anyhow::Result<Quantity> {\n    let decimal = Decimal::from_str(value).map_err(|e| {\n        anyhow::anyhow!(\"Failed to parse '{field_name}' value '{value}' into Decimal: {e}\")\n    })?;\n    let normalized = decimal.normalize();\n    let precision = (normalized.scale() as u8).min(FIXED_PRECISION);","sourceCodeStart":107,"sourceCodeEnd":143,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/dydx/src/common/parse.rs#L107-L143","documentation":"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).","triggerScenarios":"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.","commonSituations":"Prices pasted with many decimal places, values in wrong units (wei-style integers), or test/config values far outside sane market ranges.","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"],"exampleFix":"// before\nlet price = parse_price(&wei_amount, \"price\")?; // 50000000000000000000\n// after\nlet human = Decimal::from_str(&wei_amount)? / Decimal::from(10u64.pow(18));\nlet price = parse_price(&human.to_string(), \"price\")?;","handlingStrategy":"validation","validationCode":"// Bound-check magnitude before Price conversion\nfn plausible_price(d: rust_decimal::Decimal) -> bool {\n    d > rust_decimal::Decimal::ZERO && d < rust_decimal::Decimal::from(1_000_000u64)\n}","typeGuard":"fn as_price(s: &str) -> Option<Price> { parse_price(s, \"price\").ok() }","tryCatchPattern":"let price = parse_price(raw, \"price\").inspect_err(|e| log::error!(\"Price conversion failed: {e}\"))?;","preventionTips":["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"],"tags":["parsing","price","precision","dydx"],"backgroundTag":"value-out-of-range","analyzedSha":"18893faf8b356be3320add8de2f861b0b647cf06","analyzedAt":"2026-09-08T20:49:34.690Z","contentChangedAt":"2026-09-08T20:49:34.690Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}