{"record":{"id":"72e1ef78673b0075","repo":"nautechsystems/nautilus_trader","slug":"invalid-depth-depth-valid-values-are-bybit-boo","errorCode":null,"errorMessage":"invalid depth {depth}; valid values are {BYBIT_BOOK_DEPTHS:?}","messagePattern":"invalid depth (.+?); valid values are (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/adapters/bybit/src/data.rs","lineNumber":435,"sourceCode":"\n        if self.shutdown_errors.is_empty() {\n            Ok(())\n        } else {\n            let errors = std::mem::take(&mut self.shutdown_errors);\n            anyhow::bail!(\"Bybit data shutdown failed: {}\", errors.join(\"; \"))\n        }\n    }\n}\n\nfn send_data(sender: &tokio::sync::mpsc::UnboundedSender<DataEvent>, data: Data) {\n    if let Err(e) = sender.send(DataEvent::Data(data)) {\n        log::error!(\"Failed to emit data event: {e}\");\n    }\n}\n\nfn validate_orderbook_depth(depth: u32) -> anyhow::Result<()> {\n    if !BYBIT_BOOK_DEPTHS.contains(&depth) {\n        anyhow::bail!(\"invalid depth {depth}; valid values are {BYBIT_BOOK_DEPTHS:?}\");\n    }\n\n    Ok(())\n}\n\n/// Cached funding state per symbol: (funding_rate, next_funding_time, funding_interval_hour).\ntype FundingCacheEntry = (Option<String>, Option<String>, Option<String>);\n\n#[expect(clippy::too_many_arguments)]\nfn handle_ws_message(\n    message: &BybitWsMessage,\n    data_sender: &tokio::sync::mpsc::UnboundedSender<DataEvent>,\n    instruments: &AHashMap<Ustr, InstrumentAny>,\n    product_type: Option<BybitProductType>,\n    trade_subs: &Arc<AtomicSet<InstrumentId>>,\n    ticker_subs: &Arc<AtomicMap<InstrumentId, AHashSet<&'static str>>>,\n    quote_depths: &Arc<AtomicMap<InstrumentId, u32>>,\n    book_depths: &Arc<AtomicMap<InstrumentId, u32>>,","sourceCodeStart":417,"sourceCodeEnd":453,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/bybit/src/data.rs#L417-L453","documentation":"Bybit's order book websocket only supports a fixed set of depth values (BYBIT_BOOK_DEPTHS, e.g. 1, 50, 200, 500). validate_orderbook_depth rejects any requested depth outside that set before subscribing, because the exchange would reject or misinterpret the subscription.","triggerScenarios":"subscribe_book_deltas with a SubscribeBookDeltas command whose depth (or default) is not one of BYBIT_BOOK_DEPTHS — e.g. requesting depth=100 or depth=500 when the product line caps lower (test case rejects 500).","commonSituations":"Configuring a generic depth value in a strategy config that works on Binance but not Bybit; requesting max depth beyond what the Bybit product supports; copying depth settings between adapters.","solutions":["Set the subscription depth to a value listed in BYBIT_BOOK_DEPTHS for the product type","Check BYBIT_BOOK_DEPTHS in the bybit adapter crate for allowed values per product","Use the default depth (BYBIT_DEFAULT_ORDERBOOK_DEPTH) by leaving depth unset","Clamp/round your requested depth down to the nearest supported value before subscribing"],"exampleFix":"// before\nclient.subscribe_book_deltas(cmd_with_depth(500))? // rejected for this product\n// after\nclient.subscribe_book_deltas(cmd_with_depth(200))? // a BYBIT_BOOK_DEPTHS value","handlingStrategy":"validation","validationCode":"fn depth_ok(depth: u32) -> bool { BYBIT_BOOK_DEPTHS.contains(&depth) }\n// clamp before subscribe:\nlet depth = *BYBIT_BOOK_DEPTHS.iter().filter(|&&d| d <= requested).max().unwrap_or(&BYBIT_DEFAULT_ORDERBOOK_DEPTH);","typeGuard":null,"tryCatchPattern":"if let Err(e) = client.subscribe_book_deltas(cmd) {\n    log::warn!(\"depth rejected, retrying with default: {e}\");\n    client.subscribe_book_deltas(cmd_with_depth(BYBIT_DEFAULT_ORDERBOOK_DEPTH))?;\n}","preventionTips":["Consult BYBIT_BOOK_DEPTHS per product type before configuring depth","Don't copy depth configs between venues","Leave depth unset to use the adapter default","Clamp to the nearest supported depth in venue-agnostic config layers"],"tags":["bybit","orderbook","validation","depth"],"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"}