Skip to main content
Every level knows which venue it came from, so you always know where the liquidity is.

Methods

What a Book holds

A Level is price, amount, venue and symbol. A Trade is venue, symbol, id, side, price, amount, timestamp.

Venue health

Only Online venues appear in the book or receive orders. Silence is treated as a fault, not as a quiet market — a feed that stops publishing without disconnecting is what fills an order far from where you expected. Dropped connections come back on their own, with a log line when a venue leaves and one when it returns.

Streaming

Called every throttle_ms — 100ms by default. One slow handler cannot hold up another.

Average price to fill a size

Ask for the price to fill 1, 5 or 10 units and you get the average you would pay, plus the worst price you would have to accept. The gap between them is your slippage.
Each one is measured from the top of the book independently — [1, 5, 10] means “to fill 1”, “to fill 5”, “to fill 10”, not three slices in a row. Use amount_buckets instead to measure in quote currency. Then target is a notional and amount is the base size it buys, which is why both are reported:
These are a read-only view of the book. Routing never uses them — a market order is always allocated against the full per-venue book, because filling an order means knowing which venue each unit sits on, and a bucket has deliberately forgotten that. Bucketing changes what sory.book() shows you, never what place() does.
If the book cannot fill a size, that entry is left out rather than reported short. There is no average price for a fill that cannot happen.

Average price to fill a size, on some of your venues

size_buckets prices a sweep across every venue in the book. Sometimes the venues you would actually trade are a subset of that — and the difference is not small.
side is what you would do, the same as in place(): "sell" walks the bids, "buy" walks the asks. You get back a Level shaped exactly like a bucket — price is the VWAP, limit_price the worst price the sweep reaches, target what you asked for — or None when what is left cannot fill the size.
Why exclude exists. A market maker quoting on one venue and hedging on the others cannot price its quote off the whole book. The venue it is quoting on is excluded from the hedge — and it is frequently the best price in the book, because the cheapest taker fees float to the top of a fee-adjusted one. Pricing against liquidity you will never touch flatters your edge by exactly the amount that venue was better by, every time, in the same direction.size_buckets cannot answer this: it pools every venue into one number that cannot be taken apart afterwards.

Crossed books

When you merge venues, a bid on one can sit above an ask on another — especially once fees move prices around. book.crossed tells you when that happened. Set resolve_crossed: True and the overlap is trimmed out before you see it.

Trades

Set trades: True and the public tape streams alongside the book, from every venue you subscribe to.
Reading does not clear the buffer, so two consumers can both use it. Trade prices are always the venue’s own, never adjusted by your fees — you did not pay a fee on someone else’s trade.