{"record":{"id":"f2ee7181a0ef09e4","repo":"nautechsystems/nautilus_trader","slug":"invalid-negative-kline-trade-count-f2ee71","errorCode":null,"errorMessage":"invalid negative kline trade count {}","messagePattern":"invalid negative kline trade count (.+?)","errorType":"validation","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/adapters/binance/src/spot/websocket/public_json/parse.rs","lineNumber":385,"sourceCode":"    let volume = parse_non_negative_quantity(&msg.kline.volume, size_precision, \"volume\")?;\n    let quote_volume = Decimal::from_str(&msg.kline.quote_volume)\n        .with_context(|| format!(\"invalid quote volume `{}`\", msg.kline.quote_volume))?;\n    let taker_buy_base_volume =\n        Decimal::from_str(&msg.kline.taker_buy_base_volume).with_context(|| {\n            format!(\n                \"invalid taker buy base volume `{}`\",\n                msg.kline.taker_buy_base_volume\n            )\n        })?;\n    let taker_buy_quote_volume = Decimal::from_str(&msg.kline.taker_buy_quote_volume)\n        .with_context(|| {\n            format!(\n                \"invalid taker buy quote volume `{}`\",\n                msg.kline.taker_buy_quote_volume\n            )\n        })?;\n    let count = u64::try_from(msg.kline.num_trades).map_err(|_| {\n        anyhow::anyhow!(\n            \"invalid negative kline trade count {}\",\n            msg.kline.num_trades\n        )\n    })?;\n\n    let ts_event =\n        parse_millis_or_init(msg.kline.close_time, \"Spot JSON kline close time\", ts_init);\n\n    Ok(Some(BinanceBar::new(\n        bar_type,\n        open,\n        high,\n        low,\n        close,\n        volume,\n        quote_volume,\n        count,\n        taker_buy_base_volume,","sourceCodeStart":367,"sourceCodeEnd":403,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/binance/src/spot/websocket/public_json/parse.rs#L367-L403","documentation":"A kline message's `num_trades` field was negative, so the `i64` from the SBE/JSON payload could not be converted to `u64`. `parse_kline` maps any `try_from` failure to this error. A trade count can never be negative, so this indicates a corrupt or malformed kline payload.","triggerScenarios":"Binance sends a kline whose `num_trades` is a negative integer; `u64::try_from(msg.kline.num_trades)` fails inside `parse_kline` and the error is raised.","commonSituations":"Protocol/SBE decode bugs or upstream anomalies producing a negative count; running against a non-standard Binance-compatible exchange; corrupted frames from a proxy.","solutions":["Log the full kline payload and report the negative `num_trades` to Binance support as an upstream data issue.","Verify the SBE schema/decoder version matches the current Binance SBE market-data spec and update the adapter.","If connecting to a Binance clone/proxy, check its kline serialization for the `num_trades` field.","Skip the offending kline and resubscribe to the kline stream to resync."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"if msg.kline.num_trades < 0 { // skip or resync kline stream\n    return Ok(None);\n}","typeGuard":null,"tryCatchPattern":"match parse_kline(&msg) {\n    Ok(kline) => publish(kline),\n    Err(e) if e.to_string().contains(\"trade count\") => {\n        log::warn!(\"skipping malformed kline: {e}\");\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Keep the Binance SBE schema and adapter up to date.","Log full payloads of anomalous upstream data and report to the exchange.","Treat u64 conversions of signed exchange fields as fallible and guard them."],"tags":["parsing","kline","binance","rust","overflow"],"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"}