Binary Protocol Parsing For Low Latency Feeds logo

Binary Protocol Parsing For Low Latency Feeds

Community
HimanshuJ16
binary-protocol-parsing-for-low-latency-feeds

Use when decoding fixed-layout binary market data by byte offset (NASDAQ ITCH, CME MDP 3.0 SBE, Eurex T7 EMDI): frame validation, message-type dispatch, fixed-point tick prices and zero-copy buffer walking that fails loud.

Overview

PublisherHimanshuJ16
RepositoryAlgo-Trading-Skills
Skill namebinary-protocol-parsing-for-low-latency-feeds
Stars
50
Forks
7
Bundled files
5
LicenseApache-2.0
Links
  • Markdown instructions

    A SKILL.md file the model loads on demand, so it only costs tokens when a request actually matches.

  • Works with any LLM

    AI skills are plain Markdown, not provider-specific code, so this works with GPT, Claude, Gemini, Grok, or a local model.

  • 5 bundled files

    Scripts, templates, and references the model can read while it works. Files are read-only and never executed.

  • Open source

    Published by HimanshuJ16 on GitHub. Read the source before you install it.

Installation

Install the Binary Protocol Parsing For Low Latency Feeds AI skill in TypingMind to use it with any LLM, or drop it into another agent that reads SKILL.md.

1

Install in TypingMind

TypingMind installs a skill straight from its GitHub folder — it reads SKILL.md, bundles the resource files, and stores the result locally.

  1. Open the app and go to Plugins → Skills.
  2. Choose "Install from GitHub".
  3. Paste the skill folder URL below and confirm.
    https://github.com/HimanshuJ16/Algo-Trading-Skills/tree/main/skills/binary-protocol-parsing-for-low-latency-feeds
  4. Enable the skill in any chat where you want it available.
Plugins → Skills → Add skill → From GitHub URL, then paste the folder URL and press Continue.
2

Install in another agent

Any agent that reads the Agent Skills format can use this skill — copy the folder into that agent's skills directory.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/HimanshuJ16/Algo-Trading-Skills.git /tmp/Algo-Trading-Skills
mkdir -p .claude/skills
cp -r /tmp/Algo-Trading-Skills/skills/binary-protocol-parsing-for-low-latency-feeds .claude/skills/binary-protocol-parsing-for-low-latency-feeds
Restart Claude Code after copying so it picks up the new skill.

Use it in TypingMind

Enable Binary Protocol Parsing For Low Latency Feeds in any TypingMind chat and the model takes it from there. Its name and description sit in the system prompt, and the moment a request matches, the model loads the full instructions itself — you never invoke it by hand, and it costs no tokens until it is actually used.

The model loads Binary Protocol Parsing For Low Latency Feeds on its own as soon as a request matches it.

Works with any AI model

AI skills are plain Markdown instructions rather than provider-specific code, so Binary Protocol Parsing For Low Latency Feeds is not tied to the model it was written for. Install it once in TypingMind and use it with GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama, or a local model you run yourself — all on your own API keys.

  • Loaded only when it is needed

    The system prompt carries just the name and description. The instructions are fetched on the first matching request, so an idle skill costs nothing.

  • Switch models mid-chat

    Because the skill is instructions rather than code, changing model does not break it — the next model reads the same SKILL.md.

Skill instructions

This is the SKILL.md content the model loads. Read it before installing — a skill is instructions your model will follow.

Binary Protocol Parsing for Low Latency Feeds

Context & Rationale

Exchanges distribute market data as raw binary packets over UDP multicast. Text and schema-driven serialization (JSON, XML, Protocol Buffers) costs orders of magnitude more than a fixed-layout binary decode, so feed handlers read network bytes directly into application structs using precompiled layouts.

The dominant production risk in this code is not slowness — it is a silent misparse. A frame decoded against the wrong layout does not raise; it returns a plausible message with a real-looking symbol, size, and price, which then corrupts order book state and feeds bad inputs to alpha models. Every decode path in this skill therefore validates before it returns.

Core Concepts

  • Struct Unpacking: Converting contiguous bytes into primitives using a precompiled struct.Struct, with endianness stated explicitly.
  • Offset-Based Buffer Walking: Passing (buffer, offset) into the decoder rather than slicing per message. Slicing bytes copies; a memoryview plus an offset does not.
  • Fixed-Point Scaling: Exchanges transmit prices as scaled integers (ITCH scales by 10,000). The integer tick is the authoritative value; a float is a derived convenience.
  • Message-Type Dispatch: The leading type byte selects the layout. The decoder re-checks it so a dispatch bug fails loudly instead of silently.
  • Memory Slots: __slots__ (or packed structs in C++) reduces per-message memory overhead and speeds attribute access.

Quick Start

See scripts/binary_parser.py, which decodes the 36-byte NASDAQ ITCH 5.0 Add Order (No MPID Attribution, type 'A') message.

python
view = memoryview(packet)              # no copy
msg = BinaryFeedParserEngine.unpack_itch_add_order(view, offset=header_len)
book.add(msg.order_ref_id, msg.price_ticks, msg.shares)   # integer ticks

When to Use

Use this skill when writing or reviewing a feed handler that decodes fixed-layout binary market data — NASDAQ ITCH, CME MDP 3.0/SBE, Eurex T7 EMDI, or a venue's proprietary binary protocol — and you need the decode step itself to be correct and fail-loud. It applies when you are:

  • unpacking length-framed binary messages into typed application structs;
  • walking multiple concatenated messages inside a single UDP payload;
  • deciding how to carry exchange prices through the system (ticks vs floats);
  • hardening an existing parser that trusts its input.

When NOT to Use

  • Text or self-describing protocols — FIX tag=value, JSON/WebSocket feeds. Those are parsed by field name, not byte offset; see websocket-subscription-reconciliation-after-reconnect.
  • Full ITCH order book reconstruction. This skill covers the decode layer generically. For the ITCH message set (A/F/E/X/D/P) and L3 book state machine, use nasdaq-totalview-itch-feed-parsing.
  • Transport concerns — A/B multicast arbitration, gap detection, and retransmission are upstream of this skill. See exchange-multicast-feed-handling and sequence-number-gap-detection-for-feeds.
  • Latency budgeting in pure Python. CPython is appropriate for research, replay, and reference decoding; see Prerequisites for measured numbers before assuming it belongs on a production hot path.

Prerequisites

  • The venue's binary specification document, at the exact version the feed publishes. Field offsets change between protocol versions.

  • The venue's endianness, read from that spec rather than assumed — see the Common Pitfalls entry below.

  • The venue's price scaling divisor and any per-instrument overrides.

  • Python 3.10+ (@dataclass(slots=True)).

  • Realistic expectations for CPython throughput. Measured on this repo's reference implementation (CPython 3.11.15, timeit, best of 5 repeats × 200k iterations, warm cache, single core):

    • struct.Struct.unpack_from alone: ~186 ns/message
    • full unpack_itch_add_order incl. validation + dataclass: ~1.08 µs/message

    These are indicative single-machine numbers, not a specification. Re-measure on your own hardware. Sustained full-depth ITCH rates need C++/Rust/FPGA.

Workflow

  1. Frame before you parse. Read the transport's length prefix (MoldUDP64 for ITCH, the 2-byte message size field for CME MDP 3.0) and confirm the full frame is present. Never infer message length from the payload you hope is there.
  2. Dispatch on the type byte. Read the leading message-type byte and select the layout from a dispatch table. If the type is unknown, skip exactly declared_length bytes and continue — do not guess a layout, and do not abandon the packet, or you will drop every subsequent message in it.
  3. Re-validate the type inside the decoder. The decoder independently asserts the type byte matches its own layout. This is what converts a dispatch bug or an off-by-one offset from silent book corruption into an exception at the point of failure.
  4. Decode at an offset, do not slice. Pass the memoryview and an offset. Advance by the message's declared length to reach the next message.
  5. Keep prices as integer ticks. Store the raw scaled integer as the authoritative value. Convert to float only at the boundary of a component that requires one.
  6. Classify decode failures. A frame that fails validation is a data integrity event: count it, log it with the packet sequence number and byte offset, and decide explicitly whether to skip the message or drop the packet. Do not let a decode exception silently kill the feed thread.
  7. Reconcile. Periodically verify decoded state against the venue's snapshot/recovery channel; see market-data-snapshot-plus-delta-reconciliation.

Full procedure: see references/workflows.md. Standards reference: see references/standards.md. Printable pre-flight checklist: see assets/checklist.md.

Common Pitfalls

  • Assuming "network protocol" means big-endian. ITCH is big-endian (>), but CME MDP 3.0 uses Simple Binary Encoding, which is little-endian. Applying a blanket > to an SBE feed corrupts every multi-byte field while still producing structurally valid-looking messages. Read the endianness off each venue's spec.
  • Decoding a frame without checking its type byte. Feeding a type 'P' (Non-Cross Trade) frame to an Add Order decoder does not raise — it returns a well-formed message with a wrong symbol, size, and price, which is then applied to the book.
  • Silently truncating over-long symbols at encode time. Truncating a 9-character symbol to 8 mints a frame for a different instrument than the caller named.
  • Slicing the receive buffer per message. buf[i:i+36] copies on every message, defeating the point of the zero-copy path. Use an offset.
  • Treating a float price as the source of truth. For ITCH's uint32/10,000 domain the float conversion itself is exact, but float arithmetic is not associative — summing notionals across fills drifts. Aggregate in ticks.
  • Using native struct alignment. A format string with no endianness prefix uses native alignment and inserts padding: the ITCH Add Order layout measures 36 bytes with > but 44 bytes natively.
  • Assuming a 48-bit timestamp fits a 32-bit int. ITCH timestamps are 6-byte nanoseconds since midnight and must be reassembled explicitly.

Verification

  • Run python -m unittest discover -s skills/binary-protocol-parsing-for-low-latency-feeds/scripts.
  • Confirm BinaryFeedParserEngine.ADD_ORDER_FORMAT.size == 36 and that the format string begins with >.
  • Assert wire offsets independently of the format string: MsgType@0, StockLocate@1, Tracking@3, Timestamp@5, OrderRef@11, BuySell@19, Shares@20, Stock@24, Price@32.
  • Feed a frame whose type byte is not 'A' and confirm ITCHFrameError is raised rather than a populated message being returned.
  • Pack a known price (150.1234) and confirm price_ticks == 1501234 exactly.
  • Round-trip the maximum 48-bit timestamp (2**48 - 1).
  • Walk a buffer of concatenated messages by offset and confirm each decodes with the expected symbol and tick price.

Related Skills

  • nasdaq-totalview-itch-feed-parsing — the full ITCH message set and L3 order book reconstruction built on top of this decode layer.
  • exchange-multicast-feed-handling — A/B multicast arbitration and gap fill, upstream of parsing.
  • sequence-number-gap-detection-for-feeds — detecting dropped packets before decoded messages reach the book.
  • market-data-snapshot-plus-delta-reconciliation — recovering correct state after a decode failure or gap.
  • memory-mapped-ring-buffer-for-ultra-low-latency — the zero-copy buffer this parser reads from.
  • order-book-depth-processing-l2-l3 — consuming decoded messages into book state.

Bundled files

The model reads these on demand while the skill is loaded. They are exposed as readable files and are never executed.

Frequently asked questions

What does the Binary Protocol Parsing For Low Latency Feeds AI skill do?

Use when decoding fixed-layout binary market data by byte offset (NASDAQ ITCH, CME MDP 3.0 SBE, Eurex T7 EMDI): frame validation, message-type dispatch, fixed-point tick prices and zero-copy buffer walking that fails loud.

Why use Binary Protocol Parsing For Low Latency Feeds on TypingMind?

Because you install it once and use it with any model. Binary Protocol Parsing For Low Latency Feeds is plain Markdown rather than provider-specific code, so the same skill runs on GPT-5, Claude, Gemini, Grok, or a local model — and you can switch model mid-chat without it breaking. TypingMind runs on your own API keys, so you pay providers directly instead of a per-seat subscription, and your skills and chats stay in your own storage.

How do I install Binary Protocol Parsing For Low Latency Feeds in TypingMind?

Open Plugins → Skills → Install from GitHub in TypingMind and paste https://github.com/HimanshuJ16/Algo-Trading-Skills/tree/main/skills/binary-protocol-parsing-for-low-latency-feeds. TypingMind reads its SKILL.md and bundles its files and installs it as a skill you can enable per chat.

Which AI models can use Binary Protocol Parsing For Low Latency Feeds?

Any model you connect in TypingMind. AI skills are plain Markdown instructions rather than provider-specific code, so GPT, Claude, Gemini, Grok, and local models can all load this skill when a request matches it.

How many AI models can I use with Binary Protocol Parsing For Low Latency Feeds?

As many as you like. As long as a model supports skills, you can use Binary Protocol Parsing For Low Latency Feeds with it — GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama and more — all on TypingMind with your own API keys.

Is the Binary Protocol Parsing For Low Latency Feeds AI skill free?

Yes. It is published on GitHub by HimanshuJ16 under the Apache-2.0 license. You only pay your own AI provider for the tokens you use.

What are AI skills?

An AI skill is a reusable instruction bundle that teaches an AI model how to do one specific task. It follows the open Agent Skills format: a SKILL.md file with a name and description, plus any scripts, templates or reference files the model may need. The model reads the instructions only when your request matches the skill, so an installed skill costs nothing until it is used.

How are AI skills different from plugins or MCP servers?

A plugin or MCP server gives a model new tools to call — code that runs somewhere and returns a result. An AI skill gives the model knowledge and process instead: how to approach a task, which steps to follow, what good output looks like. Skills are plain Markdown, so they need no server, no API key and no runtime, and they work with any model.

View all

Set up your own AI workspace now

Get notified about new features and future giveaways by subscribing to our newsletter 👇