{"record":{"id":"168eb7482d97fe56","repo":"nautechsystems/nautilus_trader","slug":"wrong-template-id-expected-execution-report-even","errorCode":null,"errorMessage":"Wrong template ID: expected {execution_report_event_codec::SBE_TEMPLATE_ID}, received {template_id}","messagePattern":"Wrong template ID: expected (.+?), received (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/adapters/binance/src/spot/websocket/trading/decode_sbe.rs","lineNumber":77,"sourceCode":"///\n/// Returns error if the buffer is too short, the template ID is wrong,\n/// the schema ID does not match, or variable-length data is malformed.\npub fn decode_execution_report(data: &[u8]) -> anyhow::Result<BinanceSpotExecutionReport> {\n    if data.len() < HEADER_LEN {\n        anyhow::bail!(\n            \"Buffer too short for SBE header: expected {HEADER_LEN}, was {}\",\n            data.len()\n        );\n    }\n\n    let buf = ReadBuf::new(data);\n    let block_length = buf.get_u16_at(0);\n    let template_id = buf.get_u16_at(2);\n    let schema_id = buf.get_u16_at(4);\n    let version = buf.get_u16_at(6);\n\n    if template_id != execution_report_event_codec::SBE_TEMPLATE_ID {\n        anyhow::bail!(\n            \"Wrong template ID: expected {}, received {template_id}\",\n            execution_report_event_codec::SBE_TEMPLATE_ID\n        );\n    }\n\n    if schema_id != crate::spot::sbe::spot::SBE_SCHEMA_ID {\n        anyhow::bail!(\n            \"Wrong schema ID: expected {}, received {schema_id}\",\n            crate::spot::sbe::spot::SBE_SCHEMA_ID\n        );\n    }\n\n    let min_block_len = execution_report_min_block_length(version);\n    if usize::from(block_length) < min_block_len {\n        anyhow::bail!(\n            \"SBE execution report block length too short: expected at least {min_block_len}, was {block_length}\"\n        );\n    }","sourceCodeStart":59,"sourceCodeEnd":95,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/binance/src/spot/websocket/trading/decode_sbe.rs#L59-L95","documentation":"decode_execution_report validates the 8-byte SBE message header of a Binance Spot user-data binary frame before decoding. This error fires when the header's template ID is not the ExecutionReportEvent template (603), meaning the payload is a different SBE message type routed to the wrong decoder. The library bails early instead of misinterpreting bytes of another template as an execution report.","triggerScenarios":"Calling decode_execution_report with a binary payload whose SBE header (bytes 2-3) carries a template ID other than 603 — e.g. a BalanceUpdateEvent (601) or OutboundAccountPositionEvent (607) frame, an out-of-order/duplicated stream event, or a hand-built test buffer with the wrong template.","commonSituations":"Routing frames by stream name instead of parsing the template ID before dispatch; Binance changing or the user mis-mapping user-data event types; writing unit tests that reuse a captured buffer from a different event type.","solutions":["Verify the frame actually came from the executionReport user-data event before calling this decoder","Parse the SBE header's template ID first and dispatch to the matching decoder (601→balance update, 603→execution report, 607→account position)","Regenerate/update the codecs if Binance bumped the template ID in a schema revision","Fix test fixtures to use a buffer encoded with the execution_report_event_codec"],"exampleFix":"// before\nlet report = decode_execution_report(raw_frame).unwrap();\n// after\nlet template_id = u16::from_be_bytes([raw_frame[2], raw_frame[3]]);\nlet report = match template_id {\n    execution_report_event_codec::SBE_TEMPLATE_ID => decode_execution_report(raw_frame)?,\n    _ => return Err(anyhow::format_err!(\"unexpected template {template_id}\")),\n};","handlingStrategy":"validation","validationCode":"pub fn is_execution_report_frame(data: &[u8]) -> bool {\n    data.len() >= 8\n        && u16::from_be_bytes([data[2], data[3]]) == execution_report_event_codec::SBE_TEMPLATE_ID\n}","typeGuard":"fn as_execution_report(data: &[u8]) -> Option<&[u8]> {\n    (data.len() >= 8\n        && u16::from_be_bytes([data[2], data[3]]) == execution_report_event_codec::SBE_TEMPLATE_ID)\n    .then_some(data)\n}","tryCatchPattern":"match decode_execution_report(&frame) {\n    Ok(report) => handle(report),\n    Err(e) if e.to_string().contains(\"Wrong template ID\") => route_to_other_decoder(&frame),\n    Err(e) => log::warn!(\"SBE decode failed: {e}\"),\n}","preventionTips":["Dispatch SBE frames on the parsed header template ID before choosing a decoder","Keep a single header-parsing helper instead of ad-hoc byte slicing","Keep test fixtures per event type, encoded with the matching codec","Regenerate codecs whenever Binance bumps the SBE schema"],"tags":["sbe","binance","websocket","decoding"],"backgroundTag":"schema-validation-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"}