Class AsyncTickCapture
java.lang.Object
com.quantfinlib.data.AsyncTickCapture
- All Implemented Interfaces:
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 Summary
Modifier and TypeMethodDescriptionstatic AsyncTickCaptureattach(HftMarketDataBus bus, Path file, int ringCapacity) Creates the capture, subscribes it to every symbol, starts the writer.voidclose()Stops the writer (draining what remains) and closes the file.longTicks dropped because the ring was full (writer stalled) — monitor this.voidonTick(int symbolId, double price, double size, long timestampNanos) The hot path: one ring publish; a full ring drops (counted), never blocks.long
-
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:
onTickin interfaceTickListener
-
droppedTicks
public long droppedTicks()Ticks dropped because the ring was full (writer stalled) — monitor this. -
ticksWritten
public long ticksWritten() -
close
Stops the writer (draining what remains) and closes the file.- Specified by:
closein interfaceAutoCloseable- Throws:
IOException
-