{"record":{"id":"89806d5bcf687d22","repo":"nautechsystems/nautilus_trader","slug":"invalid-field-raw-at-precision-precision","errorCode":null,"errorMessage":"invalid {field}='{raw}' at precision {precision}: {e}","messagePattern":"invalid (.+?)='(.+?)' at precision (.+?): (.+?)","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/adapters/binance/src/common/parse.rs","lineNumber":225,"sourceCode":"    }\n\n    Price::from_decimal_dp(decimal, precision).ok()\n}\n\n/// Parses a required venue decimal string.\npub(crate) fn parse_required_decimal(raw: &str, field: &str) -> anyhow::Result<Decimal> {\n    Decimal::from_str(raw).map_err(|e| anyhow::anyhow!(\"invalid {field}='{raw}': {e}\"))\n}\n\n/// Parses a required venue quantity string into a `Quantity` at the given precision.\npub(crate) fn parse_required_quantity_at_precision(\n    raw: &str,\n    precision: u8,\n    field: &str,\n) -> anyhow::Result<Quantity> {\n    let decimal = parse_required_decimal(raw, field)?;\n    Quantity::from_decimal_dp(decimal, precision)\n        .map_err(|e| anyhow::anyhow!(\"invalid {field}='{raw}' at precision {precision}: {e}\"))\n}\n\n/// Parses a required venue price string into a `Price` at the given precision.\npub(crate) fn parse_required_price_at_precision(\n    raw: &str,\n    precision: u8,\n    field: &str,\n) -> anyhow::Result<Price> {\n    let decimal = parse_required_decimal(raw, field)?;\n    Price::from_decimal_dp(decimal, precision)\n        .map_err(|e| anyhow::anyhow!(\"invalid {field}='{raw}' at precision {precision}: {e}\"))\n}\n\n/// Re-precisions an existing `Quantity` to the given precision via `Decimal`.\n#[must_use]\npub(crate) fn quantity_at_precision(quantity: Quantity, precision: u8) -> Option<Quantity> {\n    Quantity::from_decimal_dp(quantity.as_decimal(), precision).ok()\n}","sourceCodeStart":207,"sourceCodeEnd":243,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/a4b06ed870971b5671d12754ea138a3ab99b1dec/crates/adapters/binance/src/common/parse.rs#L207-L243","documentation":"Second stage of required-quantity parsing: the string already parsed as a Decimal, but Quantity::from_decimal_dp cannot represent it at the requested fixed precision, so the error repeats the field, raw value, and adds the precision. Typical causes are negative values or values whose significant digits exceed what the fixed-point Quantity type can hold at that precision.","triggerScenarios":"Calls into parse_required_quantity_at_precision where the venue decimal is negative (for example '-0.001') or where magnitude/scale cannot be represented by a Quantity at the passed precision.","commonSituations":"A venue field that legitimately carries a sign (fee-adjusted balance, liquidation delta) is fed to a parser expecting an unsigned quantity; precision inferred from a different venue field mismatches the value's scale; API version drift.","solutions":["Check the raw value in the error message for a minus sign or unexpected magnitude.","Confirm the venue semantics of the field; if it is a signed delta, handle the sign upstream rather than parsing it as a quantity.","Verify how the precision argument is derived for that symbol/instrument and fix its source.","If the venue response itself is inconsistent, capture the payload and report it to the adapter maintainers."],"exampleFix":"// before: signed venue value parsed directly as a quantity\n// parse_required_quantity_at_precision(\"-0.001\", 8, \"executedQty\")?; // -> error\n\n// after: resolve the sign first (only after confirming the venue reports magnitude here)\n// let raw = raw.trim_start_matches('-');\n// parse_required_quantity_at_precision(raw, 8, \"executedQty\")?;","handlingStrategy":"validation","validationCode":"fn quantity_fits_at_precision(raw: &str, precision: u8) -> bool {\n    let Ok(d) = rust_decimal::Decimal::from_str(raw) else { return false; };\n    d.is_sign_positive() && nautilus_model::types::Quantity::from_decimal_dp(d, precision).is_ok()\n}","typeGuard":null,"tryCatchPattern":"match parse_required_quantity_at_precision(raw, precision, field) {\n    Ok(qty) => qty,\n    Err(e) => {\n        tracing::error!(%field, %raw, %precision, \"quantity conversion failed: {e:#}\");\n        return Ok(None); // degrade gracefully for this record\n    }\n}","preventionTips":["Check signed venue fields (deltas, fees, PnL) upstream and strip/branch on the sign before quantity parsing.","Confirm the precision source (tick/step-derived) matches the field being parsed.","Add fixture tests covering boundary magnitudes so scale mismatches surface in CI, not production."],"tags":["binance","quantity","precision","fixed-point","rust"],"backgroundTag":"fixed-precision-conversion-failed","analyzedSha":"a4b06ed870971b5671d12754ea138a3ab99b1dec","analyzedAt":"2026-08-16T22:54:50.089Z","schemaVersion":2},"datasetVersion":"2026-08-16T23:17:17.608Z"}