Class AsyncTickCapture

java.lang.Object
com.quantfinlib.data.AsyncTickCapture
All Implemented Interfaces:
TickListener, AutoCloseable

public final class AsyncTickCapture extends Object implements TickListener, AutoCloseable
Tick capture with the file I/O taken OFF the bus consumer thread — the hot-lane variant of TickCapture. The consumer thread only publishes into a private TickRingBuffer; a dedicated writer thread drains it into the QFLT file. A page-cache writeback, AV scan or disk hiccup then stalls the writer, never the trading loop.

The backpressure policy is the honest one for a recorder on a trading path: when the ring is full (writer stalled longer than the buffer absorbs), ticks are dropped from the capture — counted in droppedTicks(), never blocking the consumer. A recording gap you can see beats latency you can't explain. Size the ring for the worst stall you tolerate: capacity 1M ≈ 28 MB ≈ several seconds of a busy feed.

Use TickCapture when simplicity wins (research replays, capture-only sessions); use this when the same bus is trading.

  • Method Details

    • attach

      public static AsyncTickCapture attach(HftMarketDataBus bus, Path file, int ringCapacity) throws IOException
      Creates the capture, subscribes it to every symbol, starts the writer.
      Throws:
      IOException
    • onTick

      public void onTick(int symbolId, double price, double size, long timestampNanos)
      The hot path: one ring publish; a full ring drops (counted), never blocks.
      Specified by:
      onTick in interface TickListener
    • droppedTicks

      public long droppedTicks()
      Ticks dropped because the ring was full (writer stalled) — monitor this.
    • ticksWritten

      public long ticksWritten()
    • close

      public void close() throws IOException
      Stops the writer (draining what remains) and closes the file.
      Specified by:
      close in interface AutoCloseable
      Throws:
      IOException