{"record":{"id":"051dc95f96f243e6","repo":"nautechsystems/nautilus_trader","slug":"binance-spot-order-book-depth-must-be-between-1-an","errorCode":null,"errorMessage":"Binance Spot order-book depth must be between 1 and 5000","messagePattern":"Binance Spot order-book depth must be between 1 and 5000","errorType":"validation","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/adapters/binance/src/spot/data.rs","lineNumber":2398,"sourceCode":"                        end_nanos,\n                        clock.get_time_ns(),\n                        params,\n                    ));\n\n                    if let Err(e) = sender.send(DataEvent::Response(response)) {\n                        log::error!(\"Failed to send bars response: {e}\");\n                    }\n                }\n                Err(e) => log::error!(\"Bar request failed: {e:?}\"),\n            }\n        });\n\n        Ok(())\n    }\n\n    fn request_book_snapshot(&self, request: RequestBookSnapshot) -> anyhow::Result<()> {\n        let depth = request.depth.map(|value| value.get() as u32);\n        anyhow::ensure!(\n            depth.is_none_or(|value| (1..=5000).contains(&value)),\n            \"Binance Spot order-book depth must be between 1 and 5000\"\n        );\n        let http = self.http_client.clone();\n        let sender = self.data_sender.clone();\n        let instrument_id = request.instrument_id;\n        let request_id = request.request_id;\n        let client_id = request.client_id.unwrap_or(self.client_id);\n        let params = request.params;\n        let clock = self.clock;\n\n        get_runtime().spawn(async move {\n            match http.request_book_snapshot(instrument_id, depth).await {\n                Ok(book) => {\n                    let response = DataResponse::Book(BookResponse::new(\n                        request_id,\n                        client_id,\n                        instrument_id,","sourceCodeStart":2380,"sourceCodeEnd":2416,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/a4b06ed870971b5671d12754ea138a3ab99b1dec/crates/adapters/binance/src/spot/data.rs#L2380-L2416","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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)"],"exampleFix":"# before\nself.request_book_snapshot(instrument_id, depth=10000)\n\n# after: Spot depth snapshots cap at 5000\nself.request_book_snapshot(instrument_id, depth=5000)","handlingStrategy":"validation","validationCode":"const BINANCE_SPOT_VALID_DEPTHS: [u32; 8] = [5, 10, 20, 50, 100, 500, 1000, 5000];\n\nfn snap_depth(requested: u32) -> u32 {\n    BINANCE_SPOT_VALID_DEPTHS\n        .iter()\n        .rev()\n        .find(|&&d| d <= requested)\n        .copied()\n        .unwrap_or(100)\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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"],"tags":["binance","spot","order-book","depth","limit","validation"],"backgroundTag":"invalid-request-parameter","analyzedSha":"a4b06ed870971b5671d12754ea138a3ab99b1dec","analyzedAt":"2026-08-16T22:54:50.089Z","schemaVersion":2},"datasetVersion":"2026-08-16T23:17:17.608Z"}