nautechsystems/nautilus_trader · error · anyhow::Error
Binance Spot order-book depth must be between 1 and 5000
Error message
Binance Spot order-book depth must be between 1 and 5000
What it means
Binance Spot GET /api/v3/depth serves at most 5000 price levels per snapshot. The adapter validates request.depth (NonZeroU64 converted to u32) against the inclusive range 1..=5000 before spawning the snapshot task, mirroring the same check inside the HTTP client.
Source
Thrown at crates/adapters/binance/src/spot/data.rs:2398
end_nanos,
clock.get_time_ns(),
params,
));
if let Err(e) = sender.send(DataEvent::Response(response)) {
log::error!("Failed to send bars response: {e}");
}
}
Err(e) => log::error!("Bar request failed: {e:?}"),
}
});
Ok(())
}
fn request_book_snapshot(&self, request: RequestBookSnapshot) -> anyhow::Result<()> {
let depth = request.depth.map(|value| value.get() as u32);
anyhow::ensure!(
depth.is_none_or(|value| (1..=5000).contains(&value)),
"Binance Spot order-book depth must be between 1 and 5000"
);
let http = self.http_client.clone();
let sender = self.data_sender.clone();
let instrument_id = request.instrument_id;
let request_id = request.request_id;
let client_id = request.client_id.unwrap_or(self.client_id);
let params = request.params;
let clock = self.clock;
get_runtime().spawn(async move {
match http.request_book_snapshot(instrument_id, depth).await {
Ok(book) => {
let response = DataResponse::Book(BookResponse::new(
request_id,
client_id,
instrument_id,View on GitHub (pinned to a4b06ed870)
Solutions
- Use one of Binance's valid depth steps: 5, 10, 20, 50, 100, 500, 1000, 5000 (5000 for the deepest snapshot)
- Clamp user-supplied depth to the 1..=5000 range before constructing the request
- Omit depth to accept Binance's default (100 levels)
Example fix
# before self.request_book_snapshot(instrument_id, depth=10000) # after: Spot depth snapshots cap at 5000 self.request_book_snapshot(instrument_id, depth=5000)
Defensive patterns
Strategy: validation
Validate before calling
const BINANCE_SPOT_VALID_DEPTHS: [u32; 8] = [5, 10, 20, 50, 100, 500, 1000, 5000];
fn snap_depth(requested: u32) -> u32 {
BINANCE_SPOT_VALID_DEPTHS
.iter()
.rev()
.find(|&&d| d <= requested)
.copied()
.unwrap_or(100)
} Prevention
- Snapshot depth is bounded by the venue, not the instrument — cap configs at 5000 for Spot
- Prefer exact valid steps so the venue does not round for you
- Document depth caps next to the request helper so callers cannot overshoot
When it happens
Trigger: Calling request_book_snapshot (RequestBookSnapshot) with depth greater than 5000 (zero is unreachable because the field is a NonZeroU64). The ensure! at spot/data.rs:2398 fires before any network call.
Common situations: Copying full-book depth values from other venues; requesting 'complete' book depth for order-book imbalance calculations; mixing up futures and spot depth caps in shared config.
Related errors
- Binance Spot L1_MBP supports depth 1 only
- invalid Binance Futures order-book depth; valid values are {
- Binance Spot supports L1_MBP and L2_MBP order book subscript
- Binance Spot trade limit must not exceed 1000
- Spot ticker requires a BINANCE instrument
AI-assisted analysis of nautechsystems/nautilus_trader@a4b06ed870 (2026-08-16).
Data as JSON: /api/errors/051dc95f96f243e6.
Report an issue: GitHub.