Class FxTierBook
java.lang.Object
com.quantfinlib.fx.FxTierBook
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 -
Method Summary
Modifier and TypeMethodDescriptiondoublebestAsk()Best (lowest) ask across LPs at each LP's frontier tier; NaN when nobody offers.doublebestBid()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.doublebestFullAmountAsk(double size) Best single-LP full-amount ASK forsize: the lowest tier price whose clip capacity covers the whole size at one LP — one ticket, one price, no signaling.intbestFullAmountAskLp(double size) LP index behindbestFullAmountAsk(double); -1 when no LP covers the size.doublebestFullAmountBid(double size) Mirror on the bid side.intbestFullAmountBidLp(double size) LP index behindbestFullAmountBid(double); -1 when none.voidclear(int lp) Pulls an LP entirely (disconnect / last-look withdrawal).doublefullAmountPrice(int lp, boolean buy, double size) One LP's full-amount price for a clip: the tightest tier whose clip capacity coverssize, NaN when the LP doesn't quote it (or only at a malformed NaN price).intlpCount()intmaxTiers()doubleprice(int lp, boolean bid, int tier) doublesize(int lp, boolean bid, int tier) doublesweepBuyCost(double size) All-in cost of BUYINGsizeby sweeping ask tiers across LPs, cheapest tier first.doublesweepPlan(boolean buy, double size, double[] outLpQty) Sweep with a plan:outLpQty[lp]receives the quantity taken from each LP (array length ≥ lpCount, fully overwritten).doublesweepSellProceeds(double size) Mirror: proceeds of SELLINGsizeinto the bid tiers; NaN if unfillable.voidtier(int lp, boolean bid, int tier, double price, double size) Replaces one tier of one LP's ladder (tierinvalid input: '<' maxTiers).inttierCount(int lp, boolean bid) voidtierCount(int lp, boolean bid, int count) Declares how many tiers oflp's side are now active (0 pulls the side).long
-
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 (tierinvalid input: '<' maxTiers). CalltierCount(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-rangelportier— 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 oflp'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 BUYINGsizeby 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 SELLINGsizeinto 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 assweepBuyCost(double)/sweepSellProceeds(double). -
bestFullAmountAsk
public double bestFullAmountAsk(double size) Best single-LP full-amount ASK forsize: 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 behindbestFullAmountAsk(double); -1 when no LP covers the size. -
bestFullAmountBidLp
public int bestFullAmountBidLp(double size) LP index behindbestFullAmountBid(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 coverssize, 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()
-