Class AggregatedBook
java.lang.Object
com.quantfinlib.fx.AggregatedBook
Multi-venue aggregated top-of-book — the core e-FX data structure: each
liquidity provider / ECN streams its own two-sided quote, and the
aggregator maintains the composite best bid/offer with venue attribution.
Designed for the hot path:
- Zero allocation — all state lives in primitive arrays sized
at construction;
onQuote(int, double, double, double, double)and every query touch only primitives. - Single writer — one thread (the feed/aggregation thread)
calls
onQuote(int, double, double, double, double); queries from that same thread are exact. This mirrors the library's SPSC discipline: fan multiple venue feeds into one aggregation thread (e.g. via the bus) rather than locking here. - Linear rescan — venue counts in e-FX are small (5–30); rescanning a primitive array on each update is faster and simpler than maintaining a heap, and it makes venue removal (a NaN quote) trivially correct.
A venue with no quote (or an explicitly cleared one)
holds NaN and never wins the scan. Crossed composites (bid ≥ ask across
venues) are real in e-FX — latency between feeds — and are reported via
isCrossed() rather than "fixed" silently.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiondoublebestAsk()doubleintdoublebestBid()doubleSize shown by the single venue owning the best bid.intVenue index owning the best bid, −1 when no venue bids.voidclear(int venue) Pulls a venue entirely (disconnect, last-look withdrawal).booleanWhether the composite is crossed or locked (best bid ≥ best ask): common transiently in aggregated e-FX, and exactly the state arbitrage/SOR logic wants to see, not have hidden.doublemid()Composite mid; NaN until both sides are quoted.voidonQuote(int venue, double bid, double bidSize, double ask, double askSize) A venue's fresh two-sided quote (NaN on a side pulls that side).doublespread()Composite spread; NaN until both sides are quoted.doubletotalAskSizeAtBest(double tolerance) Mirror oftotalBidSizeAtBest(double)for the offer side.doubletotalBidSizeAtBest(double tolerance) Total size quoted withintoleranceof the best bid across all venues — the sweepable size at the composite level.longint
-
Constructor Details
-
AggregatedBook
public AggregatedBook(int venueCount)
-
-
Method Details
-
onQuote
public void onQuote(int venue, double bid, double bidSize, double ask, double askSize) A venue's fresh two-sided quote (NaN on a side pulls that side). Single-writer; refreshes the composite in the same call. -
clear
public void clear(int venue) Pulls a venue entirely (disconnect, last-look withdrawal). -
bestBid
public double bestBid() -
bestAsk
public double bestAsk() -
bestBidSize
public double bestBidSize()Size shown by the single venue owning the best bid. -
bestAskSize
public double bestAskSize() -
bestBidVenue
public int bestBidVenue()Venue index owning the best bid, −1 when no venue bids. -
bestAskVenue
public int bestAskVenue() -
mid
public double mid()Composite mid; NaN until both sides are quoted. -
spread
public double spread()Composite spread; NaN until both sides are quoted. -
totalBidSizeAtBest
public double totalBidSizeAtBest(double tolerance) Total size quoted withintoleranceof the best bid across all venues — the sweepable size at the composite level. -
totalAskSizeAtBest
public double totalAskSizeAtBest(double tolerance) Mirror oftotalBidSizeAtBest(double)for the offer side. -
isCrossed
public boolean isCrossed()Whether the composite is crossed or locked (best bid ≥ best ask): common transiently in aggregated e-FX, and exactly the state arbitrage/SOR logic wants to see, not have hidden. -
venueCount
public int venueCount() -
updateCount
public long updateCount()
-