HFTLeaks

How To Be First

It seems these days that every mathlete at a T20 school or layperson reading the FT is acutely aware of the methods and spoils of latency reduction, though that awareness is usually limited to telco and colocation. In the case of telco, this is a small and widely publicized subset of strategies that aspiring polymaths love to include in their ever-expanding surface-level knowledge for reasons of aesthetics. For the majority of traded volume that is not driven by New Line Networks’ (Jump, Virtu) “experimentally licensed” towers, winning is a much finer line.

What follows are some of the methods by which firms reduce tick-to-trade latency.

Byte size inference

We begin with a very common strategy, simple arbitrage between related futures contracts, options and their underlyings, and so on. We will use E-mini S&P (ES) and Micro E-mini (MES) futures. Your intuition may be to compare the prices of two (or many) instruments for an arbitrage condition, such that the ask price of contract A is less than the bid price of contract B, or vice versa. However, this can be finicky when price magnitudes are very different (e.g., ES against NQ futures), in which case we would need to construct a covariance or normalised fair value. Instead, what is done is to simply trade the lagging instrument in the same direction as a trade that sweeps multiple prices in the leading instrument.

Order book snapshots showing a hit across several price levels

In this example, a large trade in ES futures sweeps multiple prices up to 7496.50. In turn, we hit the best ask in MES futures, expecting the ask price to rise toward 7499. We prefer FOK and FAK orders because we do not want to leave an order in the book if our order is only partially filled or somebody else hits the 7496.25 offer first.

How, then, does one capture this opportunity first? I will explain this with the pseudo timing diagram below and an example from front-month E-mini futures PCAPs. If you are experienced with digital design, this should be familiar to you.

In this example, I assume the control signals of the Cisco Nexus network receive (RX) interface and a 32-bit receive cycle. We parse a CME MDP 3.0 Market Data Incremental Refresh (tag 35=X) message, which uses SBE over UDP. On MDP 3.0, a Trade Summary (tag 269=2) is the first message disseminated when a trade occurs. Whilst each packet typically contains a single FIX message, the exchange will begin to packetize multiple smaller messages (adds, deletes, and small trades) when under load. I have found that this occurs on roughly 20% of updates.

We would expect to parse the frame, update the order book, and then construct and send the order. However, many participants are able to do this in less time. How so? It is obvious that we should trigger off the Trade Summary before updating the order book, but we are able to get a bit faster than this.

In cycle 0, the rx_sof_net signal goes high, indicating the start of the frame. rx_vld_net is high when there is valid data on the receive bus (rx_data_net). On C4, we parse the IPv4 total length of 1432 bytes. On C13, we parse MsgSize from the message header. On C14, we begin to parse the SBE header, which contains the TemplateID for a Trade Summary (48). At Ethernet-frame byte offsets 78–85 (complete at C21), we parse the price of the first Trade Summary, a 64-bit integer representing the price multiplied by one billion. At byte offsets 90–93 (complete at C23), we parse the security ID, and so on.

CME Globex trade summary timing waveform

7499 You may notice a write to the transmit interface (tx_fifo_wr_en) upon receiving the trade price. Here, we write the constructed order even though we haven’t reached the end of the frame. A feature of MDP 3.0, ITCH, and other binary protocols is that they include every resting order filled in a match event in the payload. This increases packet size on larger trades, which may require splitting an event across multiple frames if it exceeds the maximum transmission unit (MTU). We can see that it is possible to infer how many levels trade out from the frame size, the number of frames per event, or both.

Scatter plot of price levels hit by packet count Scatter plot of price levels hit by packet size in bytes

All trade events that exceeded the MTU swept at least three prices in this data.
This is a very common signal. The general logic is to begin constructing a NewOrderSingle (tag 35=D) request from its template and preinitialize all static fields when we think an event is significant. We can begin to do this early because we know the frame size before reaching any message fields. By doing this, we have already completed the “detection” stage and saved ourselves tens of nanoseconds. All we need to do is validate the remaining fields (side and instrument) and perhaps use a mux to select the volume to send, usually depending on the available BBO volume for us to hit. We then finalize the checksum and mask these fields as we stream the template out of RAM.

In this example, we check whether the trade price of the first Trade Summary is greater than or less than the current midpoint of the BBO to determine whether the trade occurred at the bid or ask. You may also want to validate this against the trade side field that arrives later. This is just one of a number of features that are used. For example, it is also common to compare the exchange event time and the sending time to determine how long the exchange took to process the event, which may be indicative of trade size. On the CME, exchange delay tends to be a less useful feature because it can include implied spreads and market-by-price snapshot delays.

These signals are used for directional trading. They are also used to perform naive mass cancellation in liquidity-providing strategies and to update fair values.

Another common strategy where we can use preloaded templates is the pickoff. Very simply, if somebody adds a bid above our fair value or an offer below it, we should generally hit this order and hedge at fair value in the underlying or lead month, assuming our fair value is correct, of course. These opportunities remain abundant in options and illiquid futures months.

Order book snapshots showing a pickoff after a new offer appears

Fill Inference

Many exchanges tend to disseminate order fill notifications to customers before a trade summary is sent. On the CME, this takes the form of an ExecutionReport message (tag 35=8) over the iLink feed for the segment gateway (MSGW) or convenience gateway (CGW). Each message is enqued in match sequence as a trade is processed and tends to arrive approx. 70us ahead of the trade summary over MDP3—this delay varies by the number of orders matched in the trade event. Given this, it is common to use 1-lot orders quoted at a fixed offset from the mid-price in order to detect large trades before they are sent on MDP. These are often referred to as canary orders, though I've heard them referred to by a number of names. The practice is quite publicized, and you will no doubt find a stefan schlamp article about it—or try asking your llm.

We read the client order id (ClOrdID) at the 54 offset—this is the ID we are free to choose for ourselves. A typical implementation might involve storing canary IDs in 2 register arrays and checking for containment—at which point begin constructing an order and validate on the limit price. The strategy can be augmented with other features, particularly on exchanges which use OUCH for order entry, as the timestamp is at a nearer offser than the order ID and price. From this timestamp, it is possible to estimate exchange delay, which can be used to select volume and predict levels traded.

Order book snapshots showing a canary

Glossary

CME MDP3 Trade Summary packet

UDP payload contains one Trade Summary message (schema 1, version 13, template 48), one price level traded, and two order-detail entries. Offsets and bytes are hexadecimal. Multibyte fields are little-endian.

Trade Summary
Offset  Bytes                    Decoded value
------  -----------------------  --------------------------------------
MDP packet header (12 bytes)
0000    64 00 00 00              MsgSeqNum = 100
0004    E8 03 EF 64 BA 3F 49 18  SendingTime (ns since Unix epoch)

Message header (10 bytes)
000C    60 00                    MsgSize = 96 bytes, including this header
000E    0B 00                    BlockLength = 11 bytes
0010    30 00                    TemplateID = 48
0012    01 00                    SchemaID = 1
0014    0D 00                    Version = 13

Fixed message body (11 bytes)
0016    00 00 EF 64 BA 3F 49 18  TransactTime (ns since Unix epoch)
001E    01                       MatchEventIndicator (last trade message)
001F    00 00                    Padding

Trade summary group (3-byte header, one 32-byte entry)
0021    20 00 01                 NoMDEntries (32 bytes per entry, 1 entry)
0024    00 D0 6A 4C D1 06 00 00  MDEntryPx = 7,496,000,000,000 × 10⁻⁹ = 7,496
002C    03 00 00 00              MDEntrySize = 3 contracts
0030    B4 70 07 00              SecurityID = 487604
0034    2A 00 00 00              RptSeq = 42
0038    02 00 00 00              NumberOfOrders = 2
003C    01                       AggressorSide = buy
003D    00                       MDUpdateAction = new trade
003E    07 00 00 00              MDTradeEntryID = 7
0042    00 00                    Padding

Order-detail group (8-byte header, two 16-byte entries)
0044    10 00                    Entry block length = 16 bytes
0046    00 00 00 00 00           Padding
004B    02                       NoOrderIDEntries = 2
004C    E9 03 00 00 00 00 00 00  OrderID = 1001 (aggressing buy)
0054    03 00 00 00              LastQty = 3 contracts
0058    00 00 00 00              Padding
005C    EA 03 00 00 00 00 00 00  OrderID = 1002 (resting sell)
0064    03 00 00 00              LastQty = 3 contracts
0068    00 00 00 00              Padding

Bit 0 of MatchEventIndicator marks the last Trade Summary message for the event. Bit 7 marks the end of the full event. (CME SBE schemas, CME message header, CME Trade Summary specification)

Offset  Bytes                       decoded value
------  --------------------------  --------------------------------------
Simple Open Framing Header (4 bytes)
0000    46 01                       MessageLength = 326 bytes, including framing
0002    FE CA                       EncodingType = 0xCAFE (little-endian SBE)

SBE header (8 bytes)
0004    25 01                       BlockLength = 293 bytes
0006    0D 02                       TemplateID = 525 (Trade Outright)
0008    08 00                       SchemaID = 8
000A    09 00                       Version = 9

Fixed body (293 bytes)
000C    2A 00 00 00                 SeqNum (9726) = 42
0010    00 54 E1 CB 23 4D 06 00     UUID (39001), session identifier
0018    45 58 45 43 2D 34 32 00     ExecID (17) = EXEC-42
0020    00 00 00 00 00 00 00 00
0028    00 00 00 00 00 00 00 00
0030    00 00 00 00 00 00 00 00
0038    00 00 00 00 00 00 00 00
0040    54 52 41 44 45 52 2D 31     SenderID (5392) = TRADER-1
0048    00 00 00 00 00 00 00 00
0050    00 00 00 00
0054    4F 52 44 2D 31 30 30 32     ClOrdID (11) = ORD-1002
005C    00 00 00 00 00 00 00 00
0064    00 00 00 00
0068    7B 00 00 00 00 00 00 00     PartyDetailsListReqID (1505) = 123
0070    00 D0 6A 4C D1 06 00 00     LastPx (31) = 7,496 (PRICE9)
0078    EA 03 00 00 00 00 00 00     OrderID (37) = 1002
0080    00 D0 6A 4C D1 06 00 00     Price (44) = 7,496 (limit price)
0088    FF FF FF FF FF FF FF 7F     StopPx (99) = null
0090    00 C0 E8 98 1A 57 9D 18     TransactTime (60) = 2026-03-16 14:00:00 UTC
0098    EE C2 E8 98 1A 57 9D 18     SendingTimeEpoch (5297) = 750 ns after TransactTime
00A0    DE 02 00 00 00 00 00 00     OrderRequestID (2422) = 734
00A8    3C E5 9B B7 04 00 00 00     SecExecID (527) = 20260316476
00B0    FF FF FF FF FF FF FF FF     CrossID (548) = null
00B8    FF FF FF FF FF FF FF FF     HostCrossID (961) = null
00C0    55 53 00 00 00              Location (9537) = US
00C5    B4 70 07 00                 SecurityID (48) = 487604
00C9    03 00 00 00                 OrderQty (38) = 3
00CD    03 00 00 00                 LastQty (32) = 3
00D1    03 00 00 00                 CumQty (14) = 3
00D5    07 00 00 00                 MDTradeEntryID (37711) = 7
00D9    17 00 00 00                 SideTradeID (1506) = 23
00DD    FF FF FF FF                 TradeLinkID (820) = null
00E1    00 00 00 00                 LeavesQty (151) = 0
00E5    30 50                       TradeDate (75) = 2026-03-16
00E7    30 50                       ExpireDate (432) = 2026-03-16
00E9    32                          OrdStatus (39) = '2' (filled)
00EA    32                          OrdType (40) = '2' (limit)
00EB    02                          Side (54) = sell
00EC    00                          TimeInForce (59) = day
00ED    00                          ManualOrderIndicator (1028) = automated
00EE    00                          PossRetransFlag (9765) = false
00EF    00                          AggressorIndicator (1057) = resting order
00F0    FF                          CrossType (549) = null
00F1    00                          ExecInst (18) = no flags set
00F2    00                          ExecutionMode (5906) = null
00F3    FF                          LiquidityFlag (9373) = null
00F4    FF                          ManagedOrder (6881) = null
00F5    FF                          ShortSaleType (5409) = null
00F6    09                          Ownership (7191) = not applicable
00F7    FF FF FF FF FF FF FF 7F     DiscretionPrice (845) = null
00FF    FF FF                       TradeType (828) = null
0101    FF                          ExecRestatementReason (378) = null
0102    FF FF                       SettlDate (64) = null
0104    FF FF                       MaturityDate (541) = null
0106    FF FF FF FF FF FF FF 7F 00  CalculatedCcyLastQty (1056) = null
010F    FF FF FF FF FF FF FF 7F 00  GrossTradeAmt (381) = null
0118    FF FF FF FF FF FF FF 7F     BenchmarkPrice (6262) = null
0120    FF FF FF FF FF FF FF 7F     ReservationPrice (9562) = null
0128    FF                          PriorityIndicator (638) = null
0129    FF FF FF FF FF FF FF 7F     DailyLimitPrice (9264) = null

NoFills group
0131    0F 00 01                    NoFills (1362) = 1, entry block length = 15 bytes
0134    00 D0 6A 4C D1 06 00 00     FillPx (1364) = 7,496
013C    03 00 00 00                 FillQty (1365) = 3
0140    30 31                       FillExecID (1363) = '01'
0142    04                          FillYieldType (1622) = FIFO

NoOrderEvents group
0143    29 00 00                    NoOrderEvents (1795) = 0, entry block length = 41 bytes

NoOrderEvents entry layout (relative to the start of an entry)
Offset  Size                        Field
+0000    8 bytes                    OrderEventPx (1799)
+0008    5 bytes                    OrderEventText (1802)
+000D    4 bytes                    OrderEventExecID (1797)
+0011    4 bytes                    OrderEventQty (1800)
+0015    1 bytes                    OrderEventType (1796)
+0016    1 bytes                    OrderEventReason (1798)
+0017    9 bytes                    ContraGrossTradeAmt (5542)
+0020    9 bytes                    ContraCalculatedCcyLastQty (5971)

Offsets start at the iLink framing header in the TCP bytestream (CME Trade Outright specification, CME iLink SBE framing)