How data is recorded
∞structuralTrades, quotes and book updates, each stamped with a sequence number and a clock time. Getting the timestamps and ordering right is the difference between a real backtest and a fiction.
The idea
What this shows. A tape is just the matching engine narrating itself: typed messages (ADD, TRADE, DELETE), each carrying a sequence number and up to three timestamps. One marketable buy emits two messages that must be applied atomically, and the trade carries no aggressor flag. Miss a single sequence number and a phantom order never cancels, silently corrupting every later state – which is why gap-free capture is the integrity check.
What are the three message types on a tape?
A tape carries trades, quotes and book updates. A trade records an execution, a quote records a change to the best bid or offer, and a book update records an order being added, reduced or cancelled at any price level. Trades tell you what happened; quotes and book updates tell you what was available.
The matching engine (the limit order book) does two things all day: it rests and cancels orders, and it crosses orders into trades. The tape is the engine narrating both, message by message, in the order they happened.
A trade (a "print") gives instrument, price, size, timestamp, a trade ID and often condition codes for auction prints, odd lots or late reports. Most public trade feeds do not say which side was the aggressor, which is the whole problem of trade-sign inference. Some do: Binance's trade stream carries a flag m ("is the buyer the market maker?"). The consolidated equity tapes do not. Nasdaq went the other way: since 14 July 2014 the Buy/Sell indicator on the ITCH 5.0 Trade message is always "B", whichever side was resting (Nasdaq TotalView-ITCH 5.0 specification). A quote is a change at the top of book, the L1 stream. A book update is a change at any level, the L2 and L3 streams, from which quotes and even trades can be derived.
What is the difference between L1, L2 and L3 data?
The levels describe how much of the book a feed exposes. L1 is the top of book: best bid and ask plus the last trade. L2 is aggregated depth per price level (market-by-price). L3 is order by order (market-by-order): each order has its own ID and a place in the queue. Deeper feeds are bigger, and let you rebuild more of the microstructure.
L1 is enough to see the price and useless for modelling depth, queueing or fill probability. L2 usually shows the total resting size at each of the top 5 to 10 levels on each side. It is the standard input for most microstructure work and lets you model walking the book, but you cannot recover where a specific order sits in the queue. L3 gives every order with its ID, price, size and arrival, so the book can be rebuilt deterministically. That is what you need to study queue value and fill probability.
The granularity you can get caps the questions you can ask. Nasdaq TotalView-ITCH is order by order, covering Nasdaq-, NYSE-, NYSE American-, NYSE Arca- and BATS-listed securities traded on Nasdaq, whereas most retail "L2" is aggregated and cannot recover the queue. Most queue-position and fill-probability research quietly assumes a clean L3 tape, and few people hold one.
What are the three timestamps, and why do they differ?
A message can carry up to three timestamps: the exchange (matching-engine) timestamp, the gateway timestamp when it left the venue's edge, and your own capture timestamp. They differ by transmission and queueing delay, and only the exchange stamp orders events across instruments correctly.
The event happens in one clock domain (the engine), crosses wires and gateways (another) and is recorded in yours (a third). Each hop adds delay and jitter, and the stamps bracket where the time went. The engine stamp is the causal clock, so use it for any cross-instrument analysis: lead-lag, or the trade-sign rules that compare a trade to a contemporaneous quote. ITCH 5.0, for instance, stamps each message as a 6-byte count of nanoseconds since midnight. The gap from the gateway stamp to the engine stamp measures the venue's internal latency. The gap from capture to gateway is your own transport latency.
Serious capture stamps at the network card, disciplined by PTP, rather than in software, because operating-system scheduling jitter is larger than the latency differences you want to measure. A time.time() call in a Python handler cannot support microstructure work. Shrinking the capture gap is the job of the low-latency stack and colocation.
Why does clock synchronisation (PTP) matter?
To order events across machines, venues or instruments, every clock must agree to within microseconds, or you cannot tell which of two near-simultaneous events came first. PTP (IEEE 1588) disciplines clocks to a common reference, usually GPS, and with hardware timestamping reaches sub-microsecond accuracy. NTP is millisecond-class, adequate only for daily-bar work.
The danger is manufactured causality. If two clocks drift by a millisecond, a lead-lag measured at millisecond scale is an artefact of the clocks, not the market. IEEE 1588-2019 is the current edition of the standard: a grandmaster clock distributes time across the network and each hop timestamps in hardware.
Regulators set a floor, and the numbers differ by regime. Commission Delegated Regulation (EU) 2017/574 (RTS 25) requires firms using a high-frequency algorithmic technique to keep clocks within 100 microseconds of UTC, at 1 microsecond granularity or finer. Other electronic trading gets 1 millisecond, and voice trading, request-for-quote systems needing human intervention and negotiated trades get 1 second. Venues must meet 100 microseconds if their gateway-to-gateway latency is 1 millisecond or less, and 1 millisecond otherwise. The US Consolidated Audit Trail sets synchronisation to NIST time: 50 milliseconds for broker-dealers (FINRA Rule 6820, CAT FAQ R1) and 100 microseconds for exchanges and FINRA. Both regimes have been in force since about 2018, and competitive shops run far tighter than either. If you buy or build a tape, timestamp quality matters as much as the prices. A feed with software stamps and an undisciplined clock cannot support microstructure research, however cheap it is.
What are sequence numbers, and why must they be gap-free?
Every message on a feed carries an increasing sequence number so that the receiver can detect a missed or reordered packet: if 1004 arrives after 1002, you lost 1003 and your book is now wrong. Gap detection plus a recovery path is what makes a rebuilt book trustworthy.
Your book is a running total of every increment. Miss one and every later state is silently corrupt, with a phantom order that never cancels or a level that never clears. On Nasdaq, ITCH messages travel inside MoldUDP64 packets. Each packet header carries the sequence number of its first message and a message count, so the receiver knows exactly which numbers to expect next. A gap () means packet loss, which is routine on UDP multicast, and the receiver asks a Re-request Server for the missing range over unicast (MoldUDP64 specification v1.00).
There are two recovery routes. With redundant A/B feeds, two identical multicast streams are published, you take whichever copy of each message arrives first and fill gaps in A from B. Alternatively a snapshot or refresh channel lets you fetch a fresh book and replay increments after it. Faithful backtesting needs the same discipline: to simulate fills you must replay the exact message sequence the engine produced, which is only possible if capture is gap-free and sequence-checked. Silent gaps give a backtest that diverges from reality in ways you cannot see (backtesting & simulation).
Snapshots vs increments: how do you reconstruct the book?
Load the latest snapshot, then apply every increment whose sequence number is higher, in order. The snapshot is the full book at an instant and bounds recovery time; the increments carry the live changes. Apply the order wrongly and the book desynchronises.
Think of the snapshot as a save point and the increments as the moves since. Incremental feeds send only changes, so bandwidth follows activity rather than book size. A snapshot service lets a late joiner, or a handler that took a gap, resynchronise without replaying the whole day. Nasdaq offers its GLIMPSE snapshot service for exactly this purpose.
Crypto venues make you do the handshake yourself, and it is the classic recording bug. Binance's documentation for its USD-M futures order book stream gives the procedure: open the WebSocket and buffer events, fetch a REST depth snapshot with its lastUpdateId, drop any buffered event whose final update ID u is below lastUpdateId, and make sure the first event applied straddles it. After that, each event's pu must equal the previous event's u, otherwise you restart. Quantities are absolute, not deltas, and a quantity of zero removes the level. Skip any step and the book is silently wrong.
Professional feeds follow the same model with order-level messages. ITCH 5.0 is a pure incremental order-by-order feed with Add Order, Order Executed, Order Executed With Price, Order Cancel, Order Delete and Order Replace messages, and OUCH is the matching order-entry protocol. For how those messages look on the wire, see messaging protocols, and read the venue's own specification for the full message set.
Worked example
Here is a fragment of an illustrative tape for instrument XYZ, written in a normalised order-by-order format rather than any one venue's wire format. It is one channel, timestamps in nanoseconds since midnight, and increasing. Sequence 1001 adds 300 lots to the bid at 50.00 (order A, the best bid); 1002 adds 100 to the ask at 50.01 (order B, the best ask, so the spread is one tick); 1003 adds 400 to the bid at 49.99 (order C, a level-2 bid). Then a marketable buy arrives: 1004 is a TRADE of 100 at 50.01, and 1005 is a DELETE of order B at 50.01.
The marketable buy produced two messages in this format: the print (1004) and the update removing the resting ask (1005). They share a timestamp because they are one engine event, so apply both atomically. Treat them separately and you briefly show a trade against an offer that is still resting. Native ITCH would not look like this. A fill against a displayed order arrives as a single Order Executed message that names the resting order, and the order is considered dead when its displayed shares reach zero, so no separate delete is sent. Either way the print carries no aggressor flag in the normalised tape. You infer a buyer-initiated trade because it printed at the ask, the quote rule from trade-sign inference.
Now drop a packet. Suppose your capture jumped from seq 1003 to 1005. The gap check () fires at once and forces a recovery. Without it you would apply the delete of order B but never record the 100-lot trade, so volume would be understated and the last price stale. Had the lost message been 1005 instead, you would be left with a phantom resting ask that never cancels. In both cases every later state inherits the error unless the gap is caught. The numbers here are illustrative. The structure (message types, three timestamps, sequence numbers, snapshot plus increments) holds on every venue; field widths and codes are what you look up in the specification.
Sources
- Nasdaq. "Nasdaq TotalView-ITCH 5.0" (feed specification). nasdaqtrader.com
- Nasdaq. "MoldUDP64 Protocol Specification", v1.00. nasdaqtrader.com
- European Commission. Commission Delegated Regulation (EU) 2017/574 of 7 June 2016 (RTS 25, accuracy of business clocks), Annex, Tables 1 and 2. legislation.gov.uk (retained copy)
- FINRA. "Rule 6820. Clock Synchronization". finra.org
- CAT NMS Plan. "FAQ R1: Clock Synchronization". catnmsplan.com
- IEEE 1588-2019. "IEEE Standard for a Precision Clock Synchronization Protocol for Networked Measurement and Control Systems". standards.ieee.org
- Binance. "How to manage a local order book correctly" (USDⓈ-M futures WebSocket market streams). developers.binance.com