accumulateOrderbook
Annotate each level with the depth resting at or better than it. Totals are inclusive of the level’s own size.
import { accumulateOrderbook } from "@symmio/trading-core";
accumulateOrderbook([
{ price: 100, size: 2 },
{ price: 99, size: 3 },
]);
/** [{ price: 100, size: 2, total: 2, totalQuote: 200 },
{ price: 99, size: 3, total: 5, totalQuote: 497 }] */Parameters
levelsreadonly OrderbookLevel[]requiredOne side of a book, best price first.
Returns
OrderbookDepthLevel[]The same levels with total (cumulative base-asset size, inclusive) and totalQuote (cumulative notional, inclusive)
attached. The input is not mutated.
Why inclusive matters
An exclusive running total leaves the best bid and the best ask reading 0. Normalizing a depth bar against that gives the touch level no bar at all and understates every row by one level’s size — so the row a trader looks at first is the one drawn wrong.
The last entry’s total is the depth of the whole series, which is the value a depth bar should normalize against.
Related
groupOrderbook— usually applied first.getOrderbookDepthWithin— depth in a price band rather than per level.
Last updated on