getOrderbookDepthWithin
Measure the depth resting within a price band around the mid, per side.
import { getOrderbookDepthWithin } from "@symmio/trading-core";
const { bidQuote, askQuote, imbalance } = getOrderbookDepthWithin(book, 0.01);
/** imbalance > 0 → more bid notional than ask within ±1% of mid */Parameters
orderbookOrderbookrequiredThe book to measure.
percentnumberrequiredHalf-width of the band as a fraction of mid. 0.01 is ±1%.
Returns
OrderbookDepthSummaryPer-side size, notional, and the imbalance between them. All zero when the book has no mid because one side is empty.
percentnumberThe band that was measured, echoed back.
bidSizenumberBase-asset size resting on the bid side inside the band.
askSizenumberBase-asset size resting on the ask side inside the band.
bidQuotenumberNotional resting on the bid side inside the band.
askQuotenumberNotional resting on the ask side inside the band.
imbalancenumber(bidQuote - askQuote) / (bidQuote + askQuote), in [-1, 1]. Positive means buy-side pressure. 0 when the band
is empty on both sides.
Why a band rather than top-of-book
Top-of-book size is one order deep and moves on every cancel. A single large order five percent away moves it not at all, while a wall of small orders next to the mid moves it not at all either. Measuring a band captures both and is far harder to spoof with one resting order.
imbalance is the usual read on which way the book is leaning, and it is the natural input for a lean indicator beside a ladder.
Related
walkOrderbook— depth priced against a specific order size.accumulateOrderbook— cumulative depth per level.