Binary Protocols
Why exchanges use compact binary protocols for market data and orders. Learn how ITCH, OUCH and SBE work, how they compare with JSON and FIX, and decoding basics.
Text formats such as JSON and FIX are readable but relatively slow to parse and large on the wire. For their fastest market data and order entry, many exchanges use binary protocols: messages laid out as fixed fields of raw bytes, each at a known position and size. A program can read a price from a binary message by looking at specific bytes, without searching for delimiters or converting text to numbers. This makes binary protocols smaller, faster and more predictable, at the cost of being unreadable to humans without a decoder.
Text versus binary#
| JSON | FIX (tag and value) | Binary | |
|---|---|---|---|
| Example price field | "price":"185.50" | 44=185.50 | 4 or 8 bytes holding an integer like 1855000 |
| Human readable | Yes | Mostly | No |
| Parsing | Search and convert text | Search tags, convert text | Read fixed offsets |
| Message size | Large | Medium | Small |
| Typical use | Crypto and retail APIs | Institutional order flow | Exchange direct feeds and order entry |
Well known binary protocols#
| Protocol | Venue or body | Purpose |
|---|---|---|
| ITCH | Nasdaq (and others using the name) | Market by order data feed: adds, executions, cancels |
| OUCH | Nasdaq | Low latency order entry |
| SBE (Simple Binary Encoding) | FIX Trading Community | Standard binary encoding, used by CME's MDP 3.0 market data |
| iLink 3 | CME Group | Order entry using SBE |
| Pillar protocols | NYSE | Binary market data and order entry |
How a binary message is laid out#
A simplified "add order" message might look like this:
| Offset | Length | Field | Type |
|---|---|---|---|
| 0 | 1 | Message type ("A") | Character |
| 1 | 8 | Timestamp (nanoseconds since midnight) | Unsigned integer |
| 9 | 8 | Order reference number | Unsigned integer |
| 17 | 1 | Side ("B" or "S") | Character |
| 18 | 4 | Shares | Unsigned integer |
| 22 | 8 | Stock symbol | Text, padded |
| 30 | 4 | Price (in units of 1/10,000 dollar) | Unsigned integer |
This mirrors the style of Nasdaq ITCH, though the real specification has more fields. Prices stored as integers avoid floating point errors: 1,855,000 in units of one ten thousandth of a dollar is $185.50.
import struct
# '>' big endian, c=char, Q=8 byte uint, c, I=4 byte uint, 8s=8 bytes, I
fmt = ">cQQcI8sI"
msg_type, ts, ref, side, shares, sym, px = struct.unpack(fmt, raw[:34])
price = px / 10_000
Byte order and versions#
- Endianness: multi byte numbers can be stored big endian or little endian; the specification says which.
- Versioning: venues update protocols; decoders must check version fields and handle new message types.
- Schemas: SBE uses XML schemas from which encoders and decoders can be generated, reducing hand written errors.
Working with binary protocols#
- Read the venue specification carefully; it is the only reliable source.
- Use generated or proven decoders where available.
- Test against sample captures the venue provides.
- Track sequence numbers for gap detection. See Sequence Numbers, Dropped Packets and Out-of-Order Messages.
- Log raw bytes for replay and debugging. See Market Data Replay.
Frequently asked questions#
What is a binary protocol in trading?#
A message format where fields are stored as raw bytes at fixed positions, making messages smaller and faster to process than text formats.
What is Nasdaq ITCH?#
Nasdaq's binary market data feed, which reports every order added, executed, modified or cancelled, allowing a full order book to be built.
What is SBE?#
Simple Binary Encoding, a FIX Trading Community standard for compact binary messages, used for example in CME's market data and order entry.
Next, learn how trading systems keep their clocks precise in Clock Synchronization and PTP.
3 quick questions on this lesson. Get them all right to finish it.
Turn on JavaScript to take the quiz.
Mentioned in
- FPGAs and Hardware AccelerationTrading Infrastructure
- Lock-Free Programming and Ring BuffersTrading Infrastructure
- Exchange vs Receive Timestamps and Latency MeasurementProgramming and Data