{"record":{"id":"59a2e169d948ade6","repo":"nautechsystems/nautilus_trader","slug":"invalid-field-raw","errorCode":null,"errorMessage":"invalid {field} `{raw}`","messagePattern":"invalid (.+?) `(.+?)`","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/adapters/binance/src/spot/websocket/public_json/parse.rs","lineNumber":62,"sourceCode":"        parse::{parse_millis_or_init, parse_price_at_precision, parse_quantity_at_precision},\n    },\n    data_types::BinanceSpotTicker,\n};\n\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();","sourceCodeStart":44,"sourceCodeEnd":80,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/binance/src/spot/websocket/public_json/parse.rs#L44-L80","documentation":"parse_non_negative_quantity parses a Binance stream quantity field into a domain Quantity. It errors when the raw string is not a valid Decimal, is negative, or cannot be represented at the instrument's precision. The message names the offending field and the raw value.","triggerScenarios":"parse_book_ticker, parse_depth_diff, or parse_kline receiving a quantity string that fails Decimal::from_str (empty, non-numeric), has a negative sign, or exceeds the allowed decimal precision in Quantity::from_decimal_dp.","commonSituations":"Binance schema changes producing unexpected payload fields; instrument precision configured tighter than Binance publishes; corrupted/truncated WS frames yielding garbage strings; test fixtures with malformed values.","solutions":["Log/inspect the `{field}` and `{raw}` values in the message to see the exact malformed payload.","Verify the instrument's precision setting matches Binance's tick size for that symbol.","Confirm the message came from the expected Binance JSON schema; update parsing if Binance changed the format.","If precision mismatch is the cause, configure the instrument with Binance's published precision."],"exampleFix":"// before\nlet qty = parse_non_negative_quantity(raw, 8, \"quantity\")?; // fails when instrument precision is 2\n// after\nlet qty = parse_non_negative_quantity(raw, instrument.price_precision(), \"quantity\")?;","handlingStrategy":"validation","validationCode":"fn is_valid_quantity(raw: &str) -> bool {\n    !raw.is_empty() && rust_decimal::Decimal::from_str(raw).map(|d| !d.is_sign_negative()).unwrap_or(false)\n}","typeGuard":null,"tryCatchPattern":"match parse_non_negative_quantity(raw, precision, \"quantity\") {\n    Ok(q) => q,\n    Err(e) => { log::warn!(\"skipping malformed stream payload: {e}\"); continue; }\n}","preventionTips":["Configure instrument precision to match Binance's published tick size/precision.","Validate incoming payloads against the expected Binance stream schema before parsing.","Log the offending raw value (already in the message) to catch schema drift early.","Reject negative or empty strings at the deserialization boundary."],"tags":["parsing","binance","spot","websocket","decimal"],"backgroundTag":"schema-validation-failed","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"}