nautechsystems/nautilus_trader · error
invalid Futures kline
Error message
invalid Futures kline {} negative trade count What it means
Raised when kline.num_trades is negative and cannot be converted into the unsigned u64 count used by BinanceBar. The parser uses u64::try_from and rejects negative trade counts as invalid, since a trade count can never be negative. This normally indicates a corrupted or fabricated payload rather than genuine exchange data.
Solutions
- Inspect the raw payload's num_trades for the reported open_time; a negative value is never valid Binance data.
- Fix any local mock/proxy generating the field to emit a non-negative integer.
- Check for deserialization type mismatches (field read into a wrong-width signed type).
- Skip the offending candle and log if the source is untrusted.
Example fix
// before (mock) num_trades: -5, // after num_trades: 5u64,
Defensive patterns
Strategy: validation
Validate before calling
if kline.num_trades < 0 {
return Err(format!("negative num_trades in kline {}: {}", kline.open_time, kline.num_trades));
} Try / catch
match convert_kline(&kline) {
Ok(bar) => emit(bar),
Err(e) if e.to_string().contains("negative trade count") => {
log::error!("corrupt payload, dropping candle: {e}");
}
Err(e) => return Err(e.into()),
} Prevention
- Treat negative counts as data corruption; alert rather than retry blindly.
- Use u64 in mocks/fixtures for count fields.
- Add schema validation on ingested payloads from untrusted sources.
When it happens
Trigger: Futures kline response with num_trades < 0 (e.g. i64 underflow in a faulty mock, deserialization artifact, or hand-crafted fixture); triggered at client.rs:3320 during kline conversion.
Common situations: Custom mocks generating random signed integers for num_trades, buggy local proxies rewriting payloads, or misaligned deserialization producing wrong values.
Understand the failure class
Background: "value must be between 0 and 1" / "out of range" / "must not be negative" errors: fixing range-validation failures across open-source libraries — this error's family across 42 libraries.
Related errors
- invalid Futures kline
- invalid Futures kline
- invalid Futures kline
- Binance Futures account state request failed
- Binance Futures aggregate trade history is limited to the…
AI-assisted analysis of nautechsystems/nautilus_trader@18893faf8b (2026-09-08).
Data as JSON: /api/errors/0e0323a9562cc0ba.
Report an issue: GitHub.
Appendix: source
Thrown at crates/adapters/binance/src/futures/http/client.rs:3320
.taker_buy_base_volume
.parse::<Decimal>()
.map_err(|e| {
anyhow::anyhow!(
"invalid Futures kline {} taker buy base volume: {e}",
kline.open_time
)
})?;
let taker_buy_quote_volume = kline
.taker_buy_quote_volume
.parse::<Decimal>()
.map_err(|e| {
anyhow::anyhow!(
"invalid Futures kline {} taker buy quote volume: {e}",
kline.open_time
)
})?;
let count = u64::try_from(kline.num_trades).map_err(|_| {
anyhow::anyhow!(
"invalid Futures kline {} negative trade count",
kline.open_time
)
})?;
Ok(BinanceBar::new(
bar_type,
open,
high,
low,
close,
volume,
quote_volume,
count,
taker_buy_base_volume,
taker_buy_quote_volume,
ts_event,
ts_init,View on GitHub (pinned to 18893faf8b)