Class ItchCodec

java.lang.Object
com.quantfinlib.marketdata.ItchCodec

public final class ItchCodec extends Object
ITCH 5.0-style binary market-data codec: the message subset that drives a full-depth (L3) book — add, add-with-attribution, execute, cancel, delete, replace, and off-book trade — with the exact field layout and big-endian encoding of the Nasdaq TotalView-ITCH 5.0 specification. Styled after the spec for realism; not a certified implementation.

Decoding is a flyweight: ItchCodec.View.wrap(byte[], int) points at a message inside a caller-owned buffer and every getter reads the bytes directly — no parsing step, no objects, zero allocation. Symbols travel as a long of 8 ASCII bytes (packStock(java.lang.String)) so the hot path never touches String.

Prices are unsigned 32-bit integers with four implied decimals — i.e. the raw value is the price in 0.0001 ticks, which plugs straight into tick-indexed books like L3BookBuilder. Domain limit: this library's tick-indexed pipeline is signed-int throughout, so prices above 2³¹−1 ticks ($214,748.36) decode negative and are dropped by band checks downstream — symbols above that price (BRK.A territory) need a coarser tick or a scaled feed, the same constraint as HftOrderBook's ladder.

Encoders exist for simulators, replay tooling and tests; a production participant only decodes.

  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static final class 
    Mutable flyweight over one message in a caller-owned buffer.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final byte
     
    static final byte
     
    static final byte
     
    static final byte
     
    static final byte
     
    static final byte
     
    static final byte
     
    static final byte
     
    static final byte
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static int
    encodeAdd(byte[] buf, int off, int stockLocate, long timestampNanos, long orderRef, byte side, long shares, long packedStock, int priceTick)
    Encodes an Add Order (A); returns bytes written.
    static int
    encodeCancel(byte[] buf, int off, int stockLocate, long timestampNanos, long orderRef, long cancelledShares)
    Encodes an Order Cancel (X, partial cancel); returns bytes written.
    static int
    encodeDelete(byte[] buf, int off, int stockLocate, long timestampNanos, long orderRef)
    Encodes an Order Delete (D); returns bytes written.
    static int
    encodeExecuted(byte[] buf, int off, int stockLocate, long timestampNanos, long orderRef, long executedShares, long matchNumber)
    Encodes an Order Executed (E); returns bytes written.
    static int
    encodeReplace(byte[] buf, int off, int stockLocate, long timestampNanos, long origRef, long newRef, long shares, int priceTick)
    Encodes an Order Replace (U); returns bytes written.
    static int
    encodeTrade(byte[] buf, int off, int stockLocate, long timestampNanos, long orderRef, byte side, long shares, long packedStock, int priceTick, long matchNumber)
    Encodes a non-cross Trade (P); returns bytes written.
    static int
    length(byte type)
    Wire length of a message type; -1 for types outside the subset.
    static long
    packStock(String symbol)
    Packs up to 8 ASCII chars into a big-endian long, space-padded (ITCH alpha style).
    static String
    unpackStock(long packed)
    Inverse of packStock(java.lang.String): trailing spaces stripped.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • Method Details

    • length

      public static int length(byte type)
      Wire length of a message type; -1 for types outside the subset.
    • packStock

      public static long packStock(String symbol)
      Packs up to 8 ASCII chars into a big-endian long, space-padded (ITCH alpha style).
    • unpackStock

      public static String unpackStock(long packed)
      Inverse of packStock(java.lang.String): trailing spaces stripped. Test/logging use only.
    • encodeAdd

      public static int encodeAdd(byte[] buf, int off, int stockLocate, long timestampNanos, long orderRef, byte side, long shares, long packedStock, int priceTick)
      Encodes an Add Order (A); returns bytes written.
    • encodeExecuted

      public static int encodeExecuted(byte[] buf, int off, int stockLocate, long timestampNanos, long orderRef, long executedShares, long matchNumber)
      Encodes an Order Executed (E); returns bytes written.
    • encodeCancel

      public static int encodeCancel(byte[] buf, int off, int stockLocate, long timestampNanos, long orderRef, long cancelledShares)
      Encodes an Order Cancel (X, partial cancel); returns bytes written.
    • encodeDelete

      public static int encodeDelete(byte[] buf, int off, int stockLocate, long timestampNanos, long orderRef)
      Encodes an Order Delete (D); returns bytes written.
    • encodeReplace

      public static int encodeReplace(byte[] buf, int off, int stockLocate, long timestampNanos, long origRef, long newRef, long shares, int priceTick)
      Encodes an Order Replace (U); returns bytes written.
    • encodeTrade

      public static int encodeTrade(byte[] buf, int off, int stockLocate, long timestampNanos, long orderRef, byte side, long shares, long packedStock, int priceTick, long matchNumber)
      Encodes a non-cross Trade (P); returns bytes written.