{"record":{"id":"c6f2494f5939aa8e","repo":"nautechsystems/nautilus_trader","slug":"binance-spot-order-book-depth-must-be-between-1-an-c6f249","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":null,"httpStatus":null,"severity":"error","filePath":"crates/adapters/binance/src/spot/http/client.rs","lineNumber":3045,"sourceCode":"            .request_binance_bars(bar_type, start, end, limit)\n            .await?\n            .into_iter()\n            .map(|bar| bar.bar())\n            .collect())\n    }\n\n    /// Requests an explicit L2 order-book snapshot.\n    ///\n    /// # Errors\n    ///\n    /// Returns an error for an invalid depth, missing instrument, request failure, or invalid level.\n    pub async fn request_book_snapshot(\n        &self,\n        instrument_id: InstrumentId,\n        depth: Option<u32>,\n    ) -> anyhow::Result<OrderBook> {\n        if depth.is_some_and(|value| value == 0 || value > 5000) {\n            anyhow::bail!(\"Binance Spot order-book depth must be between 1 and 5000\");\n        }\n        let instrument = self.instrument_from_cache_by_id(instrument_id)?;\n        let params = DepthParams {\n            symbol: instrument_id.symbol.to_string(),\n            limit: depth,\n        };\n        let snapshot = self.inner.depth(&params).await?;\n        let ts_event = self.generate_ts_init();\n        Self::parse_book_snapshot_response(instrument_id, &instrument, &snapshot, ts_event)\n    }\n\n    fn parse_book_snapshot_response(\n        instrument_id: InstrumentId,\n        instrument: &InstrumentAny,\n        snapshot: &BinanceDepth,\n        ts_event: UnixNanos,\n    ) -> anyhow::Result<OrderBook> {\n        let sequence = u64::try_from(snapshot.last_update_id)","sourceCodeStart":3027,"sourceCodeEnd":3063,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/binance/src/spot/http/client.rs#L3027-L3063","documentation":"`request_book_snapshot` validates the optional depth (limit) parameter before calling Binance's /api/v3/depth: if a depth is supplied and is 0 or greater than 5000 it bails, because Binance Spot only accepts limit values in [1, 5000] (with valid discrete limits like 5, 10, 20, 50, 100, 500, 1000, 5000).","triggerScenarios":"Calling `request_book_snapshot(instrument_id, Some(depth))` with depth == 0 or depth > 5000 — e.g. `Some(0)`, `Some(10000)`, or a user-configured book depth of 10000.","commonSituations":"Configuring an OrderBook depth from a config file where 0 means 'unlimited' in the user's mind; copying Futures depth limits (which cap at 5000 levels differently or accept different values) to Spot; off-by-one or multiplier mistakes when generating depth configs.","solutions":["Pass a depth between 1 and 5000 (Binance accepts specific values: 1, 5, 10, 20, 50, 100, 500, 1000, 5000)","Pass None to use the adapter/API default depth instead of an explicit invalid value","Clamp/validate the configured depth before calling request_book_snapshot"],"exampleFix":"// before\nlet book = client.request_book_snapshot(instrument_id, Some(10_000)).await?;\n// after\nlet book = client.request_book_snapshot(instrument_id, Some(5_000)).await?;","handlingStrategy":"validation","validationCode":"fn valid_book_depth(depth: Option<u32>) -> Option<u32> {\n    depth.filter(|d| (1..=5000).contains(d))\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Clamp configured depth into 1..=5000","Use Binance's discrete limit values (5, 100, 500, 1000, 5000)","Pass None when the default depth suffices","Never encode 'unlimited' as 0 for Binance depth"],"tags":["binance","spot","orderbook","depth","validation"],"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"}