{"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":1942,"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        // Track subscription for reconnect handling\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().expect(MUTEX_POISONED);\n            *guard = guard.wrapping_add(1);\n            *guard\n        };\n\n        // Start buffering deltas for this instrument\n        self.book_buffers\n            .insert(instrument_id, BookBuffer::new(epoch));","sourceCodeStart":1924,"sourceCodeEnd":1960,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/a4b06ed870971b5671d12754ea138a3ab99b1dec/crates/adapters/binance/src/futures/data.rs#L1924-L1960","documentation":"For L2_MBP subscriptions the requested depth must be one of `BINANCE_BOOK_DEPTHS = [5, 10, 20, 50, 100, 500, 1000]` (crates/adapters/binance/src/common/consts.rs:338); omitting depth defaults to 1000. These are the levels Binance's partial book-depth streams actually offer, so any other value cannot be mapped to a stream and is rejected before the subscription is tracked for reconnect handling.","triggerScenarios":"`subscribe_book_deltas` with `book_type=BookType.L2_MBP` and depth not in the set — e.g. 25, 250, 200, 300 (depths valid on other venues but not in this adapter's constant list). Depth None is allowed and becomes 1000.","commonSituations":"Porting configs from Binance spot or other exchanges whose valid depth lists differ; assuming any positive depth is accepted; sharing a generic depth parameter (e.g. 250) across multi-venue strategies.","solutions":["Pick a depth from [5, 10, 20, 50, 100, 500, 1000]","Omit the depth argument entirely to get the default 1000-level book","If you need a custom display depth (e.g. 25), subscribe the next larger valid depth (50) and trim client-side"],"exampleFix":"# before\nactor.subscribe_order_book_deltas(instrument_id, book_type=BookType.L2_MBP, depth=250)\n\n# after\nactor.subscribe_order_book_deltas(instrument_id, book_type=BookType.L2_MBP, depth=500)","handlingStrategy":"validation","validationCode":"BINANCE_FUTURES_BOOK_DEPTHS = {5, 10, 20, 50, 100, 500, 1000}\n\ndef validate_binance_l2_depth(depth) -> int:\n    if depth is None:\n        return 1000  # adapter default\n    if depth not in BINANCE_FUTURES_BOOK_DEPTHS:\n        raise ValueError(f'depth {depth} invalid for Binance Futures; valid: {sorted(BINANCE_FUTURES_BOOK_DEPTHS)}')\n    return depth\n\nvalidate_binance_l2_depth(depth)\nactor.subscribe_order_book_deltas(instrument_id, book_type=BookType.L2_MBP, depth=depth)","typeGuard":"BINANCE_FUTURES_BOOK_DEPTHS = {5, 10, 20, 50, 100, 500, 1000}\n\ndef is_valid_binance_depth(depth) -> bool:\n    return depth in BINANCE_FUTURES_BOOK_DEPTHS","tryCatchPattern":"try:\n    actor.subscribe_order_book_deltas(instrument_id, book_type=BookType.L2_MBP, depth=depth)\nexcept Exception as e:\n    if 'Invalid depth' in str(e) and 'Binance Futures order book' in str(e):\n        nearest = min(BINANCE_FUTURES_BOOK_DEPTHS, key=lambda d: abs(d - depth))\n        actor.subscribe_order_book_deltas(instrument_id, book_type=BookType.L2_MBP, depth=nearest)\n    else:\n        raise","preventionTips":["Hardcode the adapter's depth list [5, 10, 20, 50, 100, 500, 1000] in config validation for Binance futures","Omit depth when you want the full 1000-level book","Per-venue depth lists differ — validate against the venue you subscribe, not a global list"],"tags":["binance","futures","orderbook","l2-mbp","depth"],"backgroundTag":"invalid-orderbook-depth","analyzedSha":"a4b06ed870971b5671d12754ea138a3ab99b1dec","analyzedAt":"2026-08-16T22:54:50.089Z","schemaVersion":2},"datasetVersion":"2026-08-16T23:17:17.608Z"}