getOrderbookSpread
Best prices and the gap between them.
import { getOrderbookSpread } from "@symmio/trading-core";
const spread = getOrderbookSpread(book);
if (spread) {
console.log(`${spread.spread} (${spread.spreadBps.toFixed(2)} bps)`);
}Parameters
orderbookOrderbookrequiredThe book to measure.
Returns
OrderbookSpread | undefinedThe spread, or undefined when either side is empty — a one-sided book has no spread, and reporting 0 would read as
a locked market.
bestBidnumberHighest resting bid.
bestAsknumberLowest resting ask.
spreadnumberbestAsk - bestBid, in quote-asset units. Negative when the book is crossed.
spreadBpsnumberThe spread as basis points of the mid.
midPricenumberArithmetic mid, (bestBid + bestAsk) / 2.
Notes
- Reads only the touch. Depth behind it does not move the result.
- Call it on the ungrouped book:
groupOrderbookmoves the touch prices apart and would overstate the spread. - A tight major sits well under one basis point — BTC often quotes around
0.016bps — so a single decimal reports every spread as0.0. Scale your precision to the magnitude.
Related
getOrderbookDepthWithin— liquidity around the mid.walkOrderbook— the cost of crossing that gap.
Last updated on