{"record":{"id":"c51ac60125491486","repo":"nautechsystems/nautilus_trader","slug":"failed-to-parse-field-name-value-value-int-c51ac6","errorCode":null,"errorMessage":"Failed to parse '{field_name}' value '{value}' into Quantity: {e}","messagePattern":"Failed to parse '(.+?)' value '(.+?)' into Quantity: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/adapters/dydx/src/common/parse.rs","lineNumber":145,"sourceCode":"}\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);\n    Quantity::from_decimal_dp(normalized, precision).map_err(|e| {\n        anyhow::anyhow!(\"Failed to parse '{field_name}' value '{value}' into Quantity: {e}\")\n    })\n}\n\n/// Parses a decimal string into a [`Decimal`].\n///\n/// # Errors\n///\n/// Returns an error if the string cannot be parsed into a valid decimal.\npub fn parse_decimal(value: &str, field_name: &str) -> anyhow::Result<Decimal> {\n    Decimal::from_str(value).map_err(|e| {\n        anyhow::anyhow!(\"Failed to parse '{field_name}' value '{value}' into Decimal: {e}\")\n    })\n}\n\n/// Converts [`UnixNanos`] to seconds as `i64` using integer division.\n///\n/// Uses pure integer arithmetic to avoid floating-point precision loss that can\n/// occur when converting large nanosecond timestamps (e.g., order expiry times).","sourceCodeStart":127,"sourceCodeEnd":163,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/dydx/src/common/parse.rs#L127-L163","documentation":"Second failure point in `parse_quantity`: the string parsed into a `Decimal` but `Quantity::from_decimal_dp` rejected it after normalization and precision clamping. The decimal is valid but not representable as a Nautilus `Quantity` (magnitude or precision limits).","triggerScenarios":"Calling `parse_quantity` with extremely large quantities (e.g. wei-scale integers), negative values where invalid, or precision beyond Quantity's representable range even after clamping to FIXED_PRECISION.","commonSituations":"Sizes not converted from token raw units, copy-pasted values with excessive decimals, or programmatic sizes exceeding the exchange's representable range.","solutions":["Convert raw token units to human units before parsing","Clamp/round the size to the instrument's size increment and max quantity before parsing","Inspect the wrapped `{e}` from Quantity::from_decimal_dp to see the exact constraint","Validate sign and magnitude at the call site before parsing"],"exampleFix":"// before\nlet qty = parse_quantity(\"99999999999999999999\", \"size\")?;\n// after\nlet qty = parse_quantity(&size.min(max_qty).to_string(), \"size\")?;","handlingStrategy":"validation","validationCode":"// Round to instrument size increment and cap before parsing\nfn clamp_size(d: rust_decimal::Decimal, max: rust_decimal::Decimal) -> rust_decimal::Decimal {\n    d.min(max)\n}","typeGuard":"fn as_quantity(s: &str) -> Option<Quantity> { parse_quantity(s, \"size\").ok() }","tryCatchPattern":"let qty = parse_quantity(raw, \"size\").inspect_err(|e| log::error!(\"Quantity conversion failed: {e}\"))?;","preventionTips":["Convert raw token units before parsing quantities","Respect instrument size_increment and max bounds","Reject negative or zero sizes early"],"tags":["parsing","quantity","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-14T05:17:10.506Z"}