{"record":{"id":"b1dea3b43c1e8df7","repo":"nautechsystems/nautilus_trader","slug":"failed-to-deserialize-instrument-payload","errorCode":null,"errorMessage":"Failed to deserialize instrument payload","messagePattern":"Failed to deserialize instrument payload","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/adapters/okx/src/websocket/parse.rs","lineNumber":2410,"sourceCode":"                    maker_fee,\n                    taker_fee,\n                    ts_init,\n                ) {\n                    Ok(Some(inst_any)) => Ok(Some(NautilusWsMessage::Instrument(\n                        Box::new(inst_any),\n                        Some(status),\n                    ))),\n                    Ok(None) => {\n                        log::warn!(\"Empty instrument payload: {msg:?}\");\n                        Ok(Some(NautilusWsMessage::InstrumentStatus(status)))\n                    }\n                    Err(e) => {\n                        log::warn!(\"Failed to parse instrument {inst_key}: {e}\");\n                        Ok(Some(NautilusWsMessage::InstrumentStatus(status)))\n                    }\n                }\n            } else {\n                anyhow::bail!(\"Failed to deserialize instrument payload\")\n            }\n        }\n        OKXWsChannel::BboTbt => {\n            let data_vec = parse_quote_msg_vec(\n                data,\n                instrument_id,\n                price_precision,\n                size_precision,\n                ts_init,\n            )?;\n            Ok(Some(NautilusWsMessage::Data(data_vec)))\n        }\n        OKXWsChannel::Tickers => {\n            let data_vec = parse_ticker_msg_vec(\n                data,\n                instrument_id,\n                price_precision,\n                size_precision,","sourceCodeStart":2392,"sourceCodeEnd":2428,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/okx/src/websocket/parse.rs#L2392-L2428","documentation":"OKX WebSocket message parsing failed to deserialize an instrument payload received on an instruments/status channel. The library bails with anyhow when serde cannot turn the raw `data` JSON into the expected instrument type, aborting processing of that message.","triggerScenarios":"An OKX WebSocket message on a channel mapping to OKXWsChannel::Instruments arrives whose `data` field cannot be deserialized into the expected instrument struct (e.g. OKX changed/added fields with incompatible types, message arrives with unexpected shape, or the wrong parser is used for the channel).","commonSituations":"OKX API schema updates introducing new field types; test fixtures or mocked payloads with malformed JSON; forwarding raw messages from endpoints (like event contract markets) that do not match the instrument schema.","solutions":["Log the raw message payload and compare it against the current OKX instruments channel schema in parse.rs","Update the deserialization structs/serde attributes in the OKX adapter to match the new OKX schema","Upgrade the nautilus_adapters/nautilus_trader package to a version with updated OKX parsing","Verify the message is actually routed to the correct channel parser (instruments vs event contracts)"],"exampleFix":"// before\nanyhow::bail!(\"Failed to deserialize instrument payload\")\n// after\nanyhow::bail!(\"Failed to deserialize instrument payload: {data:?}\") // include payload for diagnosis; fix serde struct to match OKX schema","handlingStrategy":"validation","validationCode":"fn is_instrument_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(\"instId\").is_some()))\n        .unwrap_or(false)\n}","typeGuard":null,"tryCatchPattern":"match parse_ws_message_data(msg) {\n    Ok(Some(m)) => handle(m),\n    Ok(None) => {},\n    Err(e) => log::warn!(\"skip malformed OKX msg: {e}\"),\n}","preventionTips":["Keep the OKX adapter updated for schema changes","Log raw payloads at debug level to diagnose drift","Pin recorded fixtures to the schema version used"],"tags":["okx","websocket","deserialization","serde"],"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-14T05:17:10.506Z"}