nautechsystems/nautilus_trader · error · anyhow::Error
invalid Binance Futures order-book depth; valid values are
Error message
invalid Binance Futures order-book depth; valid values are {:?} What it means
request_book_snapshot validates the requested order-book depth against BINANCE_BOOK_DEPTHS before calling the Binance Futures REST snapshot endpoint. Binance only serves depth snapshots at specific levels (5, 10, 20, 50, 100, 500, 1000), so any other value is rejected locally with anyhow::bail before any network call is made.
Solutions
- Set depth to one of the values listed in BINANCE_BOOK_DEPTHS (5, 10, 20, 50, 100, 500, 1000 for USD-M Futures).
- Pass None to let the adapter use its default depth.
- Clamp/snap arbitrary configured depths to the nearest valid value before calling.
Example fix
// before let book = client.request_book_snapshot(instrument_id, Some(7)).await?; // after let book = client.request_book_snapshot(instrument_id, Some(10)).await?;
Defensive patterns
Strategy: validation
Validate before calling
const VALID_DEPTHS: [u32; 7] = [5, 10, 20, 50, 100, 500, 1000];
fn is_valid_depth(d: u32) -> bool { VALID_DEPTHS.contains(&d) }
assert!(is_valid_depth(my_depth), "depth {my_depth} unsupported by Binance Futures"); Type guard
fn valid_depth(d: Option<u32>) -> bool { d.is_none() || VALID_DEPTHS.contains(&d.unwrap()) } Prevention
- Pick depth values only from the documented Binance depth tiers.
- Snap user-configured depths to the nearest valid tier at config load time.
- Pass None unless a specific depth tier is required.
When it happens
Trigger: Calling request_book_snapshot(instrument_id, Some(depth)) with a depth that is not contained in crate::common::consts::BINANCE_BOOK_DEPTHS, e.g. Some(7), Some(25), or Some(200). Passing None is fine (falls back to a default depth).
Common situations: A user config or strategy parameter supplies an arbitrary depth from a config file or CLI flag; code ported from another exchange adapter uses that exchange's depth granularity; a depth value is computed rather than picked from the allowed set.
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
- Binance Futures does not support second-level kline…
- Binance Futures L1_MBP supports depth 1 only
- Binance Spot L1_MBP supports depth 1 only
- Binance Spot order-book depth must be between 1 and 5000
- {e}
AI-assisted analysis of nautechsystems/nautilus_trader@18893faf8b (2026-09-08).
Data as JSON: /api/errors/b562ed2294b21c53.
Report an issue: GitHub.
Appendix: source
Thrown at crates/adapters/binance/src/futures/http/client.rs:3120
.request_binance_bars(bar_type, start, end, limit)
.await?
.into_iter()
.map(|bar| bar.bar())
.collect())
}
/// Requests an explicit L2 order-book snapshot.
///
/// # Errors
///
/// Returns an error for an invalid depth, missing instrument, request failure, or invalid level.
pub async fn request_book_snapshot(
&self,
instrument_id: InstrumentId,
depth: Option<u32>,
) -> anyhow::Result<OrderBook> {
if depth.is_some_and(|value| !crate::common::consts::BINANCE_BOOK_DEPTHS.contains(&value)) {
anyhow::bail!(
"invalid Binance Futures order-book depth; valid values are {:?}",
crate::common::consts::BINANCE_BOOK_DEPTHS
);
}
let (symbol, price_precision, size_precision) =
self.cached_precisions_by_id(instrument_id)?;
let params = BinanceDepthParams {
symbol,
limit: depth,
};
let snapshot = self.inner.depth(¶ms).await?;
let ts_event = self.clock.get_time_ns();
let sequence = u64::try_from(snapshot.last_update_id)
.map_err(|_| anyhow::anyhow!("invalid negative order-book update ID"))?;
let mut book = OrderBook::new(instrument_id, BookType::L2_MBP);
for (index, level) in snapshot.bids.iter().enumerate() {
let order = BookOrder::new(
OrderSide::Buy,View on GitHub (pinned to 18893faf8b)