Trading

Order Book

Virtualized bid/ask depth ladder with red asks on top, a spread row, and green bids on bottom. Presentational only — feed itbids and asks arrays.

Preview

Fullscreen
Price
Volume
Total
Spread: 1.6
(0.0024%)

Source

Copy this file to components/trading/order-book.tsx

tsx
'use client'

import * as React from 'react'
import { useVirtualizer } from '@tanstack/react-virtual'
import { cn } from '@/lib/utils'

export interface OrderBookLevel {
  price: number
  amount: number
}

export interface OrderBookProps {
  bids: OrderBookLevel[]
  asks: OrderBookLevel[]
  displayDepth?: number
  showCumulative?: boolean
  priceDecimals?: number
  amountDecimals?: number
  rowsVisible?: number
  className?: string
}

// Virtualized depth ladder: asks (red) on top, spread row, bids (green) on
// bottom. Each side sizes to its content; pass rowsVisible to cap a side's
// height and let it scroll.

Props

PropType
bids*OrderBookLevel[]
asks*OrderBookLevel[]
displayDepthnumber
showCumulativeboolean
priceDecimalsnumber
amountDecimalsnumber
rowsVisiblenumber
classNamestring