{"record":{"id":"a458fd2b581b1b55","repo":"nautechsystems/nautilus_trader","slug":"okx-only-supports-l2-mbp-order-book-deltas","errorCode":null,"errorMessage":"OKX only supports L2_MBP order book deltas","messagePattern":"OKX only supports L2_MBP order book deltas","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/adapters/okx/src/data.rs","lineNumber":1845,"sourceCode":"        // Instead, subscribe to the instrument type if not already subscribed\n        let instrument_id = cmd.instrument_id;\n        let ws = self.public_ws()?.clone();\n\n        self.spawn_ws(\n            async move {\n                ws.subscribe_instrument(instrument_id)\n                    .await\n                    .context(\"instrument type subscription\")?;\n                Ok(())\n            },\n            \"subscribe_instrument\",\n        );\n        Ok(())\n    }\n\n    fn subscribe_book_deltas(&mut self, cmd: SubscribeBookDeltas) -> anyhow::Result<()> {\n        if cmd.book_type != BookType::L2_MBP {\n            anyhow::bail!(\"OKX only supports L2_MBP order book deltas\");\n        }\n\n        if is_okx_spread_symbol(cmd.instrument_id.symbol.as_str()) {\n            // Spreads have no incremental book channel; sprd-books5 pushes a full\n            // 5-level snapshot, emitted as F_SNAPSHOT deltas to feed the book.\n            let instrument_id = cmd.instrument_id;\n            let ws = self.business_ws()?.clone();\n            let book_channels = Arc::clone(&self.book_channels);\n            let book_sync = self.book_sync.clone();\n            self.spawn_ws(\n                async move {\n                    ws.subscribe_spread_book(instrument_id)\n                        .await\n                        .context(\"spread book subscription\")?;\n                    book_channels.insert(instrument_id, OKXBookChannel::SprdBooks5);\n                    book_sync.record_subscription(instrument_id, Instant::now());\n                    Ok(())\n                },","sourceCodeStart":1827,"sourceCodeEnd":1863,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/okx/src/data.rs#L1827-L1863","documentation":"The OKX data client's `subscribe_book_deltas` only supports level-2 market-by-price order book subscriptions. OKX pushes L2 deltas via its `books` channels; any other book type (e.g. L3_MBO) has no corresponding OKX channel, so the adapter rejects the subscription up front with `anyhow::bail!`. Fix the subscription request to use `BookType::L2_MBP`.","triggerScenarios":"Calling `subscribe_book_deltas` with a `SubscribeBookDeltas` command whose `cmd.book_type` is anything other than `BookType::L2_MBP` (e.g. `L3_MBO`), either directly via a data command or through a config/request that sets a non-L2 book type for an OKX instrument.","commonSituations":"Configuring an order book subscription with `book_type = L3_MBO` copied from another venue adapter (some venues support MBO, OKX does not); generic strategy code that requests the deepest book type available without checking venue support; migrating a strategy from a L3-capable adapter to OKX.","solutions":["Change the subscription request to use `BookType::L2_MBP` for OKX instruments.","If your strategy needs L3 data, use a different venue/data source; OKX does not provide MBO feeds.","Add a pre-subscription check on `book_type` in strategy config validation to fail fast with a clear message."],"exampleFix":"// before\nlet cmd = SubscribeBookDeltas::new(instrument_id, BookType::L3_MBO, ...);\ndata_engine.execute(cmd)?;\n// after\nlet cmd = SubscribeBookDeltas::new(instrument_id, BookType::L2_MBP, ...);\ndata_engine.execute(cmd)?;","handlingStrategy":"validation","validationCode":"if book_type != BookType::L2_MBP {\n    return Err(anyhow::anyhow!(\"OKX requires BookType::L2_MBP for book deltas\"));\n}\nclient.subscribe_book_deltas(cmd)?;","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always use BookType::L2_MBP for OKX order book subscriptions.","Centralize venue capability checks in strategy config validation.","Read the adapter docs table of supported book types per venue before configuring."],"tags":["okx","order-book","unsupported-operation","market-data"],"backgroundTag":"unsupported-operation","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"}