Class Nbbo

java.lang.Object
com.quantfinlib.marketdata.Nbbo

public final class Nbbo extends Object
National Best Bid and Offer: aggregates per-venue top-of-book quotes for one symbol into the consolidated best bid/ask, the size available at those prices, and a bitmask of which venues are at the inside — the three inputs a smart order router actually consumes. The equities counterpart of fx.AggregatedBook, in integer ticks.

Zero allocation per update; single-writer (one consolidated-feed thread). Recomputation is a linear scan over venues — with the ≤ 64 venues of a real consolidated tape, a branch-predictable scan over four parallel arrays beats any incremental structure.

An optional Nbbo.Listener fires only when the NBBO actually changes (price or size at the inside), so downstream logic is naturally conflated to inside-quote updates.

  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static interface 
    Fired after the NBBO (price or inside size) changes.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
     
    static final int
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    Nbbo(int venueCount)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    long
    Total displayed size at the national best offer, across venues.
    int
    National best offer in ticks; NO_ASK when no venue offers.
    long
    Bitmask of venues quoting at the national best offer.
    long
    Total displayed size at the national best bid, across venues.
    int
    National best bid in ticks; NO_BID when no venue bids.
    long
    Bitmask of venues quoting at the national best bid (bit v = venue v).
    long
    Updates that moved the inside (price or size) — the conflation ratio.
    boolean
    Crossed market flag (NBB above NBO — locked/crossed tape condition).
    void
    Installs the (single) inside-change callback.
    boolean
    Locked market flag (NBB equal to NBO).
    double
    Mid in tick units, NaN when either side is absent.
    boolean
    onVenueDown(int venue, long timestampNanos)
    Removes a venue's quotes (feed loss / venue halt).
    boolean
    onVenueQuote(int venue, int bid, long bidSz, int ask, long askSz, long timestampNanos)
    One venue's new top of book.
    long
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • Constructor Details

    • Nbbo

      public Nbbo(int venueCount)
      Parameters:
      venueCount - number of venues (≤ 64, so venue sets fit one bitmask)
  • Method Details

    • listener

      public void listener(Nbbo.Listener l)
      Installs the (single) inside-change callback.
    • onVenueQuote

      public boolean onVenueQuote(int venue, int bid, long bidSz, int ask, long askSz, long timestampNanos)
      One venue's new top of book. Pass NO_BID/NO_ASK (or zero sizes) for an empty side; use onVenueDown(int, long) when the venue drops entirely. Returns true when the NBBO changed.
    • onVenueDown

      public boolean onVenueDown(int venue, long timestampNanos)
      Removes a venue's quotes (feed loss / venue halt). Returns true on NBBO change.
    • bidTick

      public int bidTick()
      National best bid in ticks; NO_BID when no venue bids.
    • bidSize

      public long bidSize()
      Total displayed size at the national best bid, across venues.
    • askTick

      public int askTick()
      National best offer in ticks; NO_ASK when no venue offers.
    • askSize

      public long askSize()
      Total displayed size at the national best offer, across venues.
    • bidVenues

      public long bidVenues()
      Bitmask of venues quoting at the national best bid (bit v = venue v).
    • askVenues

      public long askVenues()
      Bitmask of venues quoting at the national best offer.
    • crossed

      public boolean crossed()
      Crossed market flag (NBB above NBO — locked/crossed tape condition).
    • locked

      public boolean locked()
      Locked market flag (NBB equal to NBO).
    • midTick

      public double midTick()
      Mid in tick units, NaN when either side is absent.
    • updateCount

      public long updateCount()
    • changeCount

      public long changeCount()
      Updates that moved the inside (price or size) — the conflation ratio.