Class AggregatedBook

java.lang.Object
com.quantfinlib.fx.AggregatedBook

public final class AggregatedBook extends Object
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
    Constructor
    Description
    AggregatedBook(int venueCount)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    double
     
    double
     
    int
     
    double
     
    double
    Size shown by the single venue owning the best bid.
    int
    Venue index owning the best bid, −1 when no venue bids.
    void
    clear(int venue)
    Pulls a venue entirely (disconnect, last-look withdrawal).
    boolean
    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.
    double
    mid()
    Composite mid; NaN until both sides are quoted.
    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).
    double
    Composite spread; NaN until both sides are quoted.
    double
    totalAskSizeAtBest(double tolerance)
    Mirror of totalBidSizeAtBest(double) for the offer side.
    double
    totalBidSizeAtBest(double tolerance)
    Total size quoted within tolerance of the best bid across all venues — the sweepable size at the composite level.
    long
     
    int
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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 within tolerance of the best bid across all venues — the sweepable size at the composite level.
    • totalAskSizeAtBest

      public double totalAskSizeAtBest(double tolerance)
      Mirror of totalBidSizeAtBest(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()