{"record":{"id":"1cb7c0a651d967d6","repo":"nautechsystems/nautilus_trader","slug":"failed-to-deserialize-books-channel-data-as-vec-ok","errorCode":null,"errorMessage":"Failed to deserialize Books channel data as Vec<OKXBookMsg>","messagePattern":"Failed to deserialize Books channel data as Vec<OKXBookMsg>","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/adapters/okx/src/websocket/parse.rs","lineNumber":2483,"sourceCode":"                ts_init,\n            )?;\n            Ok(Some(NautilusWsMessage::Data(data_vec)))\n        }\n        OKXWsChannel::Books\n        | OKXWsChannel::BooksTbt\n        | OKXWsChannel::Books5\n        | OKXWsChannel::Books50Tbt => {\n            if let Ok(book_msgs) = serde_json::from_value::<Vec<OKXBookMsg>>(data) {\n                let data_vec = parse_book10_msg_vec(\n                    book_msgs,\n                    instrument_id,\n                    price_precision,\n                    size_precision,\n                    ts_init,\n                )?;\n                Ok(Some(NautilusWsMessage::Data(data_vec)))\n            } else {\n                anyhow::bail!(\"Failed to deserialize Books channel data as Vec<OKXBookMsg>\")\n            }\n        }\n        _ => {\n            log::warn!(\"Unsupported channel for message parsing: {channel:?}\");\n            Ok(None)\n        }\n    }\n}\n\n#[cfg(test)]\nmod tests {\n    use ahash::AHashMap;\n    use nautilus_core::nanos::UnixNanos;\n    use nautilus_model::{\n        data::bar::BAR_SPEC_1_DAY_LAST,\n        enums::GreeksConvention,\n        identifiers::{ClientOrderId, Symbol},\n        instruments::CryptoPerpetual,","sourceCodeStart":2465,"sourceCodeEnd":2501,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/okx/src/websocket/parse.rs#L2465-L2501","documentation":"The OKX WebSocket Books channel message could not be deserialized as a Vec<OKXBookMsg>. The parser expects the `data` field to be an array of order book update messages; anything else causes an anyhow bail.","triggerScenarios":"A Books/BBO channel WS message arrives where `data` is not an array of OKXBookMsg-compatible objects (missing fields like action/data types, non-array payload, or schema drift from OKX).","commonSituations":"OKX changes the books snapshot/update format; a depth channel message is misrouted to the Books parser; mocked or recorded payloads used in tests are incomplete.","solutions":["Inspect the raw payload and confirm it is an array of book messages matching OKX's Books channel docs","Update OKXBookMsg serde definitions in parse.rs to match the current OKX schema","Ensure the channel-to-parser mapping sends books-channel data to parse_ws_message_data with the right OKXWsChannel variant","Upgrade the adapter to a release with corrected OKX book parsing"],"exampleFix":"// before\nanyhow::bail!(\"Failed to deserialize Books channel data as Vec<OKXBookMsg>\")\n// after\nanyhow::bail!(\"Failed to deserialize Books channel data as Vec<OKXBookMsg>: {data:?}\") // and align OKXBookMsg fields with OKX docs","handlingStrategy":"validation","validationCode":"fn is_book_payload(msg: &serde_json::Value) -> bool {\n    msg.get(\"data\")\n        .and_then(|d| d.as_array())\n        .map(|a| a.iter().all(|o| o.get(\"action\").is_some() || o.get(\"data\").is_some()))\n        .unwrap_or(false)\n}","typeGuard":null,"tryCatchPattern":"let data: Vec<OKXBookMsg> = match serde_json::from_value(payload) {\n    Ok(d) => d,\n    Err(e) => { log::warn!(\"book parse failed: {e}\"); return; }\n};","preventionTips":["Confirm channel routing maps books messages to the Books parser","Track OKX changelog for depth format updates","Validate recorded test payloads against OKXBookMsg"],"tags":["okx","websocket","orderbook","deserialization"],"backgroundTag":"json-unmarshal-failed","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"}