{"record":{"id":"89b1eea724b26db6","repo":"nautechsystems/nautilus_trader","slug":"invalid-depth-depth-for-binance-futures-order-bo","errorCode":null,"errorMessage":"Invalid depth {depth} for Binance Futures order book. Valid values: {BINANCE_BOOK_DEPTHS:?}","messagePattern":"Invalid depth (.+?) for Binance Futures order book\\. Valid values: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/adapters/binance/src/futures/data.rs","lineNumber":1996,"sourceCode":"                *subscriptions.entry(cmd.instrument_id).or_insert(0) += 1;\n            });\n            self.subscribe_top_of_book(cmd.instrument_id);\n            return Ok(());\n        }\n\n        if cmd.book_type != BookType::L2_MBP {\n            anyhow::bail!(\"Binance Futures supports L1_MBP and L2_MBP order book subscriptions\");\n        }\n        anyhow::ensure!(\n            !self.l1_book_subscriptions.contains_key(&cmd.instrument_id),\n            \"cannot subscribe L1_MBP and L2_MBP for the same Binance Futures instrument\"\n        );\n\n        let instrument_id = cmd.instrument_id;\n        let depth = cmd.depth.map_or(1000, |d| d.get() as u32);\n\n        if !BINANCE_BOOK_DEPTHS.contains(&depth) {\n            anyhow::bail!(\n                \"Invalid depth {depth} for Binance Futures order book. \\\n                Valid values: {BINANCE_BOOK_DEPTHS:?}\"\n            );\n        }\n\n        self.book_subscriptions.insert(instrument_id, depth);\n\n        // Bump epoch to invalidate any in-flight snapshot from a prior subscription\n        let epoch = {\n            let mut guard = self.book_epoch.write();\n            *guard = guard.wrapping_add(1);\n            *guard\n        };\n\n        self.book_buffers\n            .insert(instrument_id, BookBuffer::new(epoch));\n\n        log::debug!(\"OrderBook snapshot rebuild for {instrument_id} @ depth {depth} starting\");","sourceCodeStart":1978,"sourceCodeEnd":2014,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/binance/src/futures/data.rs#L1978-L2014","documentation":"The requested order book depth must be one of the Binance-supported depth levels listed in BINANCE_BOOK_DEPTHS (e.g. 5/10/20/50/100/500/1000). If not provided, depth defaults to 1000; an explicitly provided unsupported depth bails.","triggerScenarios":"subscribe_book_deltas with cmd.depth set to a value not in BINANCE_BOOK_DEPTHS (e.g. 25, 400, 2000).","commonSituations":"Setting depth in strategy config copied from another venue's conventions, or computing depth dynamically without validating against the venue's allowed set.","solutions":["Set cmd.depth to one of the values in BINANCE_BOOK_DEPTHS (e.g. 5, 10, 20, 50, 100, 500, 1000)","Remove the explicit depth to use the default 1000","Snap/round your configured depth to the nearest valid value before subscribing"],"exampleFix":"// before\ndepth: Some(NonZeroUsize::new(400).unwrap()),\n// after\ndepth: Some(NonZeroUsize::new(500).unwrap()),","handlingStrategy":"validation","validationCode":"const DEPTHS: [u32; 7] = [5,10,20,50,100,500,1000];\nlet depth = cmd.depth.map_or(1000, |d| d.get() as u32);\nassert!(DEPTHS.contains(&depth), \"unsupported depth {depth}\");","typeGuard":"fn is_valid_depth(depth: Option<NonZeroUsize>) -> bool {\n    const DEPTHS: [u32; 7] = [5,10,20,50,100,500,1000];\n    depth.map_or(true, |d| DEPTHS.contains(&(d.get() as u32)))\n}","tryCatchPattern":"match client.subscribe_book_deltas(cmd).await {\n    Err(e) if e.to_string().contains(\"Invalid depth\") => return Err(anyhow::anyhow!(\"snap depth to a valid Binance value\")),\n    other => other,\n}","preventionTips":["Use only Binance-supported depth values","Snap configured depth to nearest valid level at startup","Leave depth unset to accept the 1000 default"],"tags":["rust","order-book","depth","validation"],"backgroundTag":"invalid-argument-value","analyzedSha":"18893faf8b356be3320add8de2f861b0b647cf06","analyzedAt":"2026-09-08T20:49:34.690Z","contentChangedAt":"2026-09-08T20:49:34.690Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}