@somnia-chain/markets-sdk / index / quoteBinaryStakeOverBook
Function: quoteBinaryStakeOverBook()
quoteBinaryStakeOverBook(
book,side,stake,oneCollateral,params):BinaryStakeQuote|null
Defined in: packages/sdk/src/derivedReads.ts:622
Convert a collateral stake into a market BUY by walking the live book — so the quoted shares and payout match what the order will actually fill, not an optimistic top-of-book estimate. The inverse of quoteBinaryOrderOverBook: that sizes cost from a quantity; this sizes quantity from a collateral budget.
The sweep buys down the asks cheapest-first, accumulating shares while the escrow at the running protective price (the worst level touched) stays within the stake — the max loss never exceeds it. A pricier level lowers that ceiling, so the sweep naturally stops once the next level can't fit. The protective limit is then padded with a slippage cushion (so the IOC still crosses if the book ticks up before it lands), aligned UP to the tick grid, capped a tick below one collateral; the quantity is re-fit to the stake at the padded price and snapped DOWN to a whole lot, so the escrow can never exceed the stake.
Returns null when nothing is fillable — empty book, a stake too small to
buy a single lot (or the pool's minQuantity), or degenerate grid params
(tickSize/lotSize/oneCollateral/stake ≤ 0).
Parameters
book
The live four-sided book (NO sides pre-inverted).
side
"BUY_YES" (Up) or "BUY_NO" (Down).
stake
bigint
Collateral budget, raw units.
oneCollateral
bigint
10^quoteDecimals — one whole outcome share.
params
The pool's tick/lot grid + slippage policy.
Returns
BinaryStakeQuote | null