Order book
A React component in Beamline's Trading category.
Asks, spread and bids with cumulative depth bars, grouping, change flashes and keyboard price picking.
Use it for
- Any order-entry screen: shows liquidity and lets the trader pick a price.
- A docked column at 200–400px (stacked, folding Total first) or a wide tile (sides apart, a Value column).
Not for
- Visualising liquidity over a price range → depth-chart.
Anatomy
- header (title, stale chip, grouping select)
- column headers (Price, Size, Value from 28rem, Total)
- stacked: asks (farthest first), spread row, bids
- split (from 36rem): spread row on top, bids at the inline start reading toward the seam, asks at the inline end
- spread row (last price + ▲/▼, spread and %; while a row is probed: average price, size and value of the range)
- row (price, size, value, total, depth bar from the spread's side, pick ring)
Variants
- layout: stacked (default), split, auto (split once the book is 36rem wide)
- density: compact (20px rows), default (24px), comfortable (28px)
- depth: a number of rows per side, fill (as many as the book's height holds)
States
- live: depth bars change by transform inside fixed row boxes, without displacing layout on a tick
- grouped (a new grouping fades in)
- stale (caller's chip in the header; levels stay readable and pickable)
- empty
- row hover / focus: the range from the spread to the row is lit, its far edge ruled, and the spread row reads its average price, size and value
- row press (darkens at 0ms) and pick (an accent ring that fades where the price was picked)
- row focus (inset ring)
- room: under 16rem Total folds (the depth bar still draws it) and the spread's % folds under 22rem; from 28rem a Value column (price × size) joins; with layout auto, from 36rem the sides stand apart
- Density: explicit instance prop, then scoped component default, then managed root density; omitted static-scope density stays inherited. Changes keep row identity and focus.
Keyboard
- Tab enters the rows (one tab stop)
- ↑/↓, Home/End move along a side (stacked: through the whole book)
- ←/→ cross to the other side at the same depth (split)
- Enter/Space sends the price to onPriceSelect
- focus on a row reads its range in the spread row, like pointing at it
Motion
Rows are places, not prices: a row keeps its place by depth and its figures change in it, so focus and the eye stay put while the market moves. A level whose size changed tints its cell in its side's colour and fades over 600ms (a level that only scrolled into view does not). Row hover and the probed range arrive at 0ms and leave over --pui-motion-out; the range's reading takes the spread's place without moving anything. A pick shows an accent ring that fades over three fade-out steps (a fade, so reduced motion keeps it). A new last price flashes once in its direction where it stands, like the price ticker. A new grouping fades in. Reduced motion: no size tint, values still update.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
bids / asks (required) | Level[] ([price, size]) | — | bids: Bid price and size levels from the market feed. Required. asks: Ask price and size levels from the market feed. Required. |
tick | number | — | Market tick size; sets price precision. |
groupings | number[] | — | Grouping steps offered in the header, e.g. [0.5, 1, 5, 10]. The first is the default. |
grouping / onGroupingChange | number | — | grouping: Controlled grouping; omit to use defaultGrouping. onGroupingChange: Reports price grouping after a change; no callback by default. |
depth | number | 'fill' | 12 | Rows shown per side, or "fill": as many as the book's height holds (give it a height). |
layout | 'auto'|'stacked'|'split' | 'stacked' | "stacked" (default): asks over bids; "split": bids and asks side by side; "auto": split once the book is 36rem wide (a tile that can be docked narrow or opened wide). |
last / lastDirection | number / 'up'|'down' | — | last: Last traded price and its direction, shown in the spread row. lastDirection: Direction of the last price change; omitted or null by default to show no direction indicator. |
onPriceSelect | (price, side) => void | — | Clicking or pressing Enter on a row sends its price here — typically into the order ticket. |
density | 'compact'|'default'|'comfortable' | — | Row height 20 / 24 / 28 px. Omitted: the nearest scope's density (default 24). |
stale | ReactNode | — | Caller-owned stale description, e.g. "Stale · 12s": shown as a chip in the header; the levels stay readable. |
style / ref | CSSProperties / native Ref | — | style: Inline styles on the documented visual root; no inline overrides by default. ref: Receives the documented root element; no ref by default. |
classNames | OrderBookClassNames | — | Classes for the named visual parts; no part overrides by default. |
style | CSSProperties | — | Inline styles on the documented visual root; no inline overrides by default. |
bids (required) | Level[] | — | Bid price and size levels from the market feed. Required. |
asks (required) | Level[] | — | Ask price and size levels from the market feed. Required. |
grouping | number | — | Controlled grouping; omit to use defaultGrouping. |
onGroupingChange | ((step: number) => void) | — | Reports price grouping after a change; no callback by default. |
sizeDecimals | number | — | Maximum fractional digits used for trade sizes. Defaults to 4. |
last | number | null | — | Last traded price and its direction, shown in the spread row. |
lastDirection | "up" | "down" | null | — | Direction of the last price change; omitted or null by default to show no direction indicator. |
base | string | — | Base asset label used with trade sizes. Defaults to "Size". |
quote | string | — | Quote currency shown with prices or totals. Defaults to "Price". |
className | string | — | Classes on the documented visual root; no override by default. |
ref | Ref<HTMLDivElement> | — | Receives the documented root element; no ref by default. |
defaultGrouping | number | — | Initial grouping when uncontrolled; defaults to the first groupings entry or tick. |
Built from
Used in
Import
import { OrderBook } from "@beamline/order-book";
Get it
Order book is part of Beamline UI. Install the parts you need in your React app as compiled packages or editable source. Get Beamline · Connect your agent
More in Trading
- Price chart: Candles, line or area price chart with volume, OHLC legend and reference lines, built for live ticks.
- Market heatmap: Treemap of markets sized by weight and coloured by change, grouped by sector, with hatched no-data tiles.
- Options chain: Calls and puts for one expiry around a centre column of strikes: bid, ask, implied volatility, delta, volume and open interest, the money shaded in, a…
- Depth chart: Cumulative bid and ask depth as stepped areas around the mid, with hover readout.
- Ticker tape: A continuously scrolling row of symbols with price, change and mini trend; anyone can hold it: hover, keyboard focus or a tap.
- Watchlist: A selectable, sortable list of markets with mini trends, prices, changes and stars.
- Trades tape: Recent trades, newest first, with side glyphs, large-print marking and one-time arrival flashes.
- Order ticket: Buy/sell order entry with limit, market and stop types, % of balance, inline validation and a live cost summary.
- Swap form: Exchange one token for another: type what you pay (or Max), pick each token from a searchable list with balances, and the form quotes what you receive…
- Positions table: Open positions with live unrealised PnL, liquidation warnings and close actions.
- P&L calendar: A trader's month at a glance: every trading day's profit or loss in its cell, shaded deeper the bigger it was in the gain or loss colour and marked ▲ or…
- Price ticker: Symbol, last price with a directional flash, 24h change and stats.
- Funding countdown: Perpetual funding rate with who pays, and a live countdown ring to the next funding.