MMTMMT Docs
Data Sources

Order Book

Order book snapshots with per-level accessors and native depth helpers.

data.BOOK exposes the current order book snapshot for the subscribed exchange, symbol, and timeframe.

data.BOOK supports aggregated exchange strings such as "binancef:bybitf".

const book = subscribe(data.BOOK)

Functions

Snapshot Metadata

book.unix(offset?) -> number
book.binSize(offset?) -> number
book.numLevels(offset?) -> number
book.numBids(offset?) -> number
book.numAsks(offset?) -> number

Top of Book

book.bestBid(offset?) -> number
book.bestAsk(offset?) -> number
book.mid(offset?) -> number

Per-Level Accessors

book.askPrice(level, offset?) -> number
book.bidPrice(level, offset?) -> number
book.askSize(level, offset?) -> number
book.bidSize(level, offset?) -> number

Native Helpers

book.depth(refPrice, outerPct, opts?, offset?) -> BookDepth | null
book.imbalance(refPrice, outerPct, opts?, offset?) -> BookImbalance | null

Batch Helpers

book.depthMany(refPrice, requests, offset?) -> Array<BookDepth | null>
book.imbalanceMany(refPrice, requests, offset?) -> Array<BookImbalance | null>

Parameters:

  • offset?: optional bar offset on the BOOK subscription clock
  • level: zero-based level index
  • refPrice: finite reference price greater than 0
  • outerPct: percent distance from refPrice, finite and >= 0

BOOK Snapshot Accessors Were Removed

book.data() and book.dataView() are deprecated for BOOK subscriptions and now throw a migration error. Use the accessors and native helpers on this page instead.

depth() and imbalance() Options

{
  innerPct?: number,
  mode?: "cumulative" | "differential",
  unit?: "quote" | "base",
  distanceDecay?: number
}
  • innerPct: inner exclusion band for differential mode
  • mode: "cumulative" includes everything from the inside out; "differential" excludes the inner band
  • unit: "quote" reports quote-side value, "base" reports base quantity
  • distanceDecay: optional weighting factor that reduces farther levels

depthMany() / imbalanceMany() Request Shape

{
  outerPct: number,
  opts?: {
    innerPct?: number,
    mode?: "cumulative" | "differential",
    unit?: "quote" | "base",
    distanceDecay?: number
  }
}

Both batch helpers share one refPrice across all requests and return results in request order.

Result Shapes

// BookDepth
{
  unix: number,
  binSize: number,
  bidValue: number,
  askValue: number,
  bidQty: number,
  askQty: number,
  bidLevels: number,
  askLevels: number
}

// BookImbalance
{
  unix: number,
  bid: number,
  ask: number,
  ratio: number
}

Helpers return null when the requested slot is missing.

Example

//@version=2
indicator("Book Imbalance", false)
const book = subscribe(data.BOOK)

function onBar(index) {
  const mid = book.mid()
  if (!(mid > 0)) return

  const imbalance = book.imbalance(mid, 1.5, {
    innerPct: 0.5,
    mode: "differential",
    unit: "quote"
  })
  if (!imbalance) return

  plotHistogram("Imbalance", imbalance.ratio, {
    color: imbalance.ratio >= 0 ? color.teal : color.orange
  })
}

On this page