{"record":{"id":"42a7dcf08cb46d99","repo":"nautechsystems/nautilus_trader","slug":"invalid-field-raw-e-42a7dc","errorCode":null,"errorMessage":"invalid {field} `{raw}`: {e}","messagePattern":"invalid (.+?) `(.+?)`: (.+?)","errorType":"validation","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/adapters/binance/src/spot/websocket/public_json/parse.rs","lineNumber":66,"sourceCode":"\nfn parse_positive_price(raw: &str, precision: u8, field: &str) -> anyhow::Result<Price> {\n    parse_price_at_precision(raw, precision)\n        .ok_or_else(|| anyhow::anyhow!(\"invalid {field} `{raw}`\"))\n}\n\nfn parse_positive_quantity(raw: &str, precision: u8, field: &str) -> anyhow::Result<Quantity> {\n    parse_quantity_at_precision(raw, precision)\n        .ok_or_else(|| anyhow::anyhow!(\"invalid {field} `{raw}`\"))\n}\n\nfn parse_non_negative_quantity(raw: &str, precision: u8, field: &str) -> anyhow::Result<Quantity> {\n    let decimal = Decimal::from_str(raw).with_context(|| format!(\"invalid {field} `{raw}`\"))?;\n    if decimal.is_sign_negative() {\n        anyhow::bail!(\"invalid {field} `{raw}`\");\n    }\n\n    Quantity::from_decimal_dp(decimal, precision)\n        .map_err(|e| anyhow::anyhow!(\"invalid {field} `{raw}`: {e}\"))\n}\n\n/// Parses a trade message into a `TradeTick`.\n///\n/// # Errors\n///\n/// Returns an error if price or quantity fields cannot be parsed.\npub fn parse_trade(\n    msg: &BinanceSpotTradeMsg,\n    instrument: &InstrumentAny,\n    ts_init: UnixNanos,\n) -> anyhow::Result<TradeTick> {\n    let instrument_id = instrument.id();\n    let price_precision = instrument.price_precision();\n    let size_precision = instrument.size_precision();\n\n    let price = parse_positive_price(&msg.price, price_precision, \"trade price\")?;\n    let size = parse_positive_quantity(&msg.quantity, size_precision, \"trade quantity\")?;","sourceCodeStart":48,"sourceCodeEnd":84,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/binance/src/spot/websocket/public_json/parse.rs#L48-L84","documentation":"A quantity field from a Binance Spot market-data event (book ticker, depth diff, kline) is negative or could not be converted to a `Quantity` at the required precision. `parse_non_negative_quantity` parses the string as a `Decimal`, rejects sign-negative values, then converts at the given precision; failures carry the underlying conversion error `{e}`.","triggerScenarios":"A book ticker, depth diff, or kline message contains a quantity string like `\"-0.5\"`, an unparseable value, or a decimal whose scale exceeds the instrument precision so `Quantity::from_decimal_dp` fails with an overflow/rounding error.","commonSituations":"Corrupt or out-of-order depth diffs with negative deltas applied incorrectly; stale instrument precision metadata; Binance format changes; a kline with a negative base-asset volume field.","solutions":["Refresh instrument definitions so the configured precision matches what Binance sends for the symbol.","Inspect the logged message (`invalid {field} \\`{raw}\\`: {e}`) to see the exact offending value and conversion error.","Apply depth diffs in the correct order (or resync via a depth snapshot) so negative quantities do not appear.","Guard stream processing to skip malformed events and reconnect/resync depth rather than aborting."],"exampleFix":"// before: applying depth diffs from a stale buffer -> negative quantity\n// after: resync when a diff's UpdateFinalFailedEvent / sequence gap is detected\nif msg.final_update_id < last_update_id + 1 { depth_client.resync(symbol).await?; }","handlingStrategy":"validation","validationCode":"fn valid_non_negative_quantity(raw: &str, precision: u8) -> bool {\n    raw.parse::<rust_decimal::Decimal>()\n        .map(|d| !d.is_sign_negative() && d.scale() <= u32::from(precision))\n        .unwrap_or(false)\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Maintain depth-diff sequencing: resync from a snapshot on any update-id gap instead of applying diffs blindly.","Refresh instrument precision metadata regularly.","Skip-and-log malformed market-data events rather than propagating a hard failure."],"tags":["parsing","precision","negative-value","websocket","binance"],"backgroundTag":"invalid-argument-value","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"}