Class WebSocketFeed
java.lang.Object
com.quantfinlib.feed.WebSocketFeed
- All Implemented Interfaces:
AutoCloseable
Live market data over WebSocket into the
HftMarketDataBus — the
last mile that lets the capture/replay, paper-trading and analytics stack
run on real ticks. Pure JDK (java.net.http WebSocket
client), pluggable FeedParser per exchange
(BinanceTradeParser ships as the reference), automatic reconnection
with exponential backoff, and an optional subscription message for
exchanges that require one after connecting.
Wire once, and everything downstream just works:
HftMarketDataBus bus = new HftMarketDataBus();
TickCapture capture = TickCapture.attach(bus, Path.of("session.qflt"));
bus.start();
try (WebSocketFeed feed = new WebSocketFeed(
BinanceTradeParser.streamUri("BTCUSDT", "ETHUSDT"),
new BinanceTradeParser(), bus)) {
feed.start();
// strategies subscribe to the bus; the session is being recorded
}
Threading: the JDK invokes WebSocket listener methods sequentially per connection, and reconnect epochs never overlap, so the bus's single-producer contract holds. Published tick timestamps are the exchange's event time (millis → nanos), so recorded sessions replay with true market pacing.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()booleanlonglongvoidstart()Connects and blocks until the first connection is established.voidlongwithReconnect(int maxAttempts, long initialBackoffMillis) withSubscribeMessage(String message) Text frame sent right after connecting (exchanges with subscribe protocols).
-
Constructor Details
-
WebSocketFeed
-
-
Method Details
-
withSubscribeMessage
Text frame sent right after connecting (exchanges with subscribe protocols). -
withReconnect
-
start
Connects and blocks until the first connection is established.- Throws:
IOException
-
start
- Throws:
IOException
-
isConnected
public boolean isConnected() -
messagesReceived
public long messagesReceived() -
tradesPublished
public long tradesPublished() -
reconnectCount
public long reconnectCount() -
close
public void close()- Specified by:
closein interfaceAutoCloseable
-