Book

Resting limit orders in the order book for the active symbol. The script re-runs on every book update while running.

book.bid / book.ask

Two arrays of price levels, best-first.

  • book.bid[0] / book.ask[0] are best bid / best ask.
  • price is a real price. size is resting quantity at that level.
  • Zero-size levels are removed.
API
book.bid // BookLevel[] - resting buy orders, highest price first
book.ask // BookLevel[] - resting sell orders, lowest price first

interface BookLevel { price: number; size: number }

book.at / book.coverage

The book as of a past moment. book.at(timestampMs) returns the newest stored snapshot at or before that time, or null when no snapshot covers it.

  • Snapshots are sampled roughly every 200ms, so the one returned can be up to that much older than the time you asked for - .time says exactly when it was taken.
  • book.coverage() is the span snapshots exist for: the pre-roll before the replay start plus whatever has played. It is far shorter than the tape - treat uncovered time as unknown, not as an empty book.
  • Book history loads because something asks for it: enabling an indicator that calls book.at or book.coverage loads the pre-roll, exactly as drawing the depth heatmap does.
Displayed size when a trade printed
for (const trade of tape) {
  const snap = book.at(trade.timestamp)
  if (!snap) continue // outside book.coverage()

  const resting = trade.side === "buy" ? snap.ask : snap.bid
  const displayed = resting.find((l) => l.price === trade.levels[0].price)
  // fills beyond displayed size came from hidden liquidity
}

interface BookSnapshot { time: number; bid: BookLevel[]; ask: BookLevel[] }