Class OrderBook
Which lane this is in: this is the research-grade venue
model — used by the microstructure fuzz tests, queue analytics and
simulations — NOT part of the measured ultra-low-latency path. The
library's sub-microsecond numbers are participant-side
(tick → strategy/quoter → risk gate → order ring → venue adapter); in that
architecture matching happens at the exchange, not in this process, so no
order on the hot path ever touches this class. Internally it deliberately
favors clarity over allocation discipline (TreeMap<Double,…>
boxing, per-order objects, iterators) — adequate for simulation, and
exactly what a venue-grade core must NOT do. The venue-grade sibling is
HftOrderBook (dense integer-tick ladder, pooled intrusive nodes,
primitive id map, zero allocation) — and its correctness is defined BY
this class: a model-based equivalence test drives both books with
identical random operation streams and demands identical state.
Keeps message counters (orders, cancels, trades) for order-to-trade ratio and surveillance analytics. Single-threaded by design: drive it from one strategy/simulation thread (or the HFT bus consumer thread).
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceFill callback: maker is the resting order, taker the incoming one. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddTradeListener(OrderBook.TradeListener listener) doublebestAsk()longdoublebestBid()longbooleancancel(long orderId) Cancels a resting order.longlongTotal resting quantity on a side across its bestmaxLevels.List<double[]> Price/quantity pairs for the given side's bestmaxLevels(side = the resting liquidity side: BUY returns bids).doublemid()order(long orderId) longdoubleOrder-to-trade ratio: messages (orders + cancels) per trade.longqtyAhead(long orderId) Quantity queued ahead of the given resting order at its price level.doublespread()longsubmitLimit(Side side, double price, long quantity, long timestampNanos) Submits a limit order: matches any crossing liquidity, then rests the remainder.longsubmitMarket(Side side, long quantity, long timestampNanos) Submits a market order; any unfilled remainder is discarded.symbol()long
-
Constructor Details
-
OrderBook
-
-
Method Details
-
symbol
-
addTradeListener
-
submitLimit
Submits a limit order: matches any crossing liquidity, then rests the remainder. Returns the order id (usable forcancel(long)andqtyAhead(long)while any quantity rests). -
submitMarket
Submits a market order; any unfilled remainder is discarded. Returns filled quantity. -
cancel
public boolean cancel(long orderId) Cancels a resting order. Returns false if unknown or fully filled. -
bestBid
public double bestBid() -
bestAsk
public double bestAsk() -
bestBidSize
public long bestBidSize() -
bestAskSize
public long bestAskSize() -
mid
public double mid() -
spread
public double spread() -
levels
-
depth
Total resting quantity on a side across its bestmaxLevels. -
qtyAhead
public long qtyAhead(long orderId) Quantity queued ahead of the given resting order at its price level. -
order
-
orderCount
public long orderCount() -
cancelCount
public long cancelCount() -
tradeCount
public long tradeCount() -
orderToTradeRatio
public double orderToTradeRatio()Order-to-trade ratio: messages (orders + cancels) per trade.
-