Class FxTierBook

java.lang.Object
com.quantfinlib.fx.FxTierBook

public final class FxTierBook extends Object
Tiered multi-LP FX book: the depth structure e-FX actually has. Equities venues publish one anonymous order book; FX liquidity providers each stream a private ladder of size tiers — 1M at 1.08500/02, 5M at 1.08498/04, 10M wider still — and the practical questions are per-clip: what does 20M actually cost if I sweep (sweepBuyCost(double)/sweepSellProceeds(double)), and which single LP fills the whole clip at one price (bestFullAmountAsk(double)/bestFullAmountBid(double) — the full-amount convention that avoids signaling the market with a spray of children).

AggregatedBook remains the top-of-book composite; this class holds the tiers underneath it. Zero allocation: fixed lpCount × maxTiers primitive arrays, caller-owned scratch for sweep plans, single writer (the feed/aggregation thread). Tiers are expected best-first per LP (tier 0 = tightest), exactly as LP streams publish them; sizes are per-tier clip capacity, prices are the all-in rate for a clip up to that size.

  • Constructor Summary

    Constructors
    Constructor
    Description
    FxTierBook(int lpCount, int maxTiers)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    double
    Best (lowest) ask across LPs at each LP's frontier tier; NaN when nobody offers.
    double
    Best (highest) bid across LPs, taken at each LP's FRONTIER tier — the first well-formed one — so a malformed tier 0 (NaN/zero) masks nothing, consistent with how sweeps and full-amount queries read the same ladder.
    double
    bestFullAmountAsk(double size)
    Best single-LP full-amount ASK for size: the lowest tier price whose clip capacity covers the whole size at one LP — one ticket, one price, no signaling.
    int
    bestFullAmountAskLp(double size)
    LP index behind bestFullAmountAsk(double); -1 when no LP covers the size.
    double
    bestFullAmountBid(double size)
    Mirror on the bid side.
    int
    bestFullAmountBidLp(double size)
    LP index behind bestFullAmountBid(double); -1 when none.
    void
    clear(int lp)
    Pulls an LP entirely (disconnect / last-look withdrawal).
    double
    fullAmountPrice(int lp, boolean buy, double size)
    One LP's full-amount price for a clip: the tightest tier whose clip capacity covers size, NaN when the LP doesn't quote it (or only at a malformed NaN price).
    int
     
    int
     
    double
    price(int lp, boolean bid, int tier)
     
    double
    size(int lp, boolean bid, int tier)
     
    double
    sweepBuyCost(double size)
    All-in cost of BUYING size by sweeping ask tiers across LPs, cheapest tier first.
    double
    sweepPlan(boolean buy, double size, double[] outLpQty)
    Sweep with a plan: outLpQty[lp] receives the quantity taken from each LP (array length ≥ lpCount, fully overwritten).
    double
    sweepSellProceeds(double size)
    Mirror: proceeds of SELLING size into the bid tiers; NaN if unfillable.
    void
    tier(int lp, boolean bid, int tier, double price, double size)
    Replaces one tier of one LP's ladder (tier invalid input: '<' maxTiers).
    int
    tierCount(int lp, boolean bid)
     
    void
    tierCount(int lp, boolean bid, int count)
    Declares how many tiers of lp's side are now active (0 pulls the side).
    long
     

    Methods inherited from class java.lang.Object

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

    • FxTierBook

      public FxTierBook(int lpCount, int maxTiers)
  • Method Details

    • tier

      public void tier(int lp, boolean bid, int tier, double price, double size)
      Replaces one tier of one LP's ladder (tier invalid input: '<' maxTiers). Call tierCount(int, boolean, int) after the last tier of an update so partially written ladders are never visible to queries from the same thread's later logic.
      Throws:
      IllegalArgumentException - on an out-of-range lp or tier — the flat layout means an unchecked overflow would silently land in the NEXT LP's ladder, which is the one failure mode a price store must never have
    • tierCount

      public void tierCount(int lp, boolean bid, int count)
      Declares how many tiers of lp's side are now active (0 pulls the side).
    • clear

      public void clear(int lp)
      Pulls an LP entirely (disconnect / last-look withdrawal).
    • bestBid

      public double bestBid()
      Best (highest) bid across LPs, taken at each LP's FRONTIER tier — the first well-formed one — so a malformed tier 0 (NaN/zero) masks nothing, consistent with how sweeps and full-amount queries read the same ladder. NaN when nobody bids.
    • bestAsk

      public double bestAsk()
      Best (lowest) ask across LPs at each LP's frontier tier; NaN when nobody offers.
    • sweepBuyCost

      public double sweepBuyCost(double size)
      All-in cost of BUYING size by sweeping ask tiers across LPs, cheapest tier first. Returns the notional paid (Σ px×qty), or NaN when the book cannot fill the size — a partial sweep is not a price. Zero allocation (internal scratch; single writer).
    • sweepSellProceeds

      public double sweepSellProceeds(double size)
      Mirror: proceeds of SELLING size into the bid tiers; NaN if unfillable.
    • sweepPlan

      public double sweepPlan(boolean buy, double size, double[] outLpQty)
      Sweep with a plan: outLpQty[lp] receives the quantity taken from each LP (array length ≥ lpCount, fully overwritten). Returns notional as sweepBuyCost(double)/sweepSellProceeds(double).
    • bestFullAmountAsk

      public double bestFullAmountAsk(double size)
      Best single-LP full-amount ASK for size: the lowest tier price whose clip capacity covers the whole size at one LP — one ticket, one price, no signaling. NaN when no LP quotes the size.
    • bestFullAmountBid

      public double bestFullAmountBid(double size)
      Mirror on the bid side.
    • bestFullAmountAskLp

      public int bestFullAmountAskLp(double size)
      LP index behind bestFullAmountAsk(double); -1 when no LP covers the size.
    • bestFullAmountBidLp

      public int bestFullAmountBidLp(double size)
      LP index behind bestFullAmountBid(double); -1 when none.
    • fullAmountPrice

      public double fullAmountPrice(int lp, boolean buy, double size)
      One LP's full-amount price for a clip: the tightest tier whose clip capacity covers size, NaN when the LP doesn't quote it (or only at a malformed NaN price). Public because it IS the full-amount convention — routers must consume it, not re-derive it.
    • lpCount

      public int lpCount()
    • maxTiers

      public int maxTiers()
    • tierCount

      public int tierCount(int lp, boolean bid)
    • price

      public double price(int lp, boolean bid, int tier)
    • size

      public double size(int lp, boolean bid, int tier)
    • updateCount

      public long updateCount()