Order Book

Bids and asks with cumulative depth. The bar is the running total from the top of book, not the size at that level — what matters when taking liquidity is how much sits between you and a price.

src/components/ui/order-book.tsx

About

From the component's own source, where it was written.

Bids and asks with cumulative depth.

The depth bar is the *cumulative* total from the top of book down, not the size at that single level. Per-level bars are the common mistake and they misrepresent the book completely: what matters when you are about to take liquidity is how much sits between you and a price, which is a running sum.

Asks are rendered ascending but displayed bottom-up so the spread sits in the middle, which is the convention every trader reads without thinking.

Install

npx astralyx-ui add order-book

Usage

import { OrderBook } from '@/components/ui/order-book'

<OrderBook bids={bids} asks={asks} quoteSymbol="USD" baseSymbol="BTC" />

Composer

Change the props and the source below follows.

Price (USD)Size (BTC)
67,241.200.6120
67,242.800.9450
67,244.101.7330
67,245.900.4880
67,247.302.2140
67,249.000.6670
Spread2.800.004%
67,238.400.8420
67,237.101.2040
67,235.800.3180
67,234.202.1060
67,232.900.7740
67,231.501.4820
Props
tsx
<OrderBook bids={bids} asks={asks} depth={6} />

Examples

Book

API

Generated from the source, so it cannot fall behind the code. One table per exported component, then hooks, functions and types.

OrderBook

Extends ComponentProps<'div'>.

PropTypeDefaultDescription
bidsOrderLevel[]required{ price, size }. Sorted internally, so the caller need not.
asksOrderLevel[]required{ price, size }. Sorted internally, so the caller need not.
depthnumber8Per-level bars are the common mistake and misrepresent the book — this is a running sum on one shared scale across both sides.
pricePrecisionnumber2—
sizePrecisionnumber4—
localestring'en-GB'—
quoteSymbolstring——
baseSymbolstring——
totalHeaderReactNode'Total'—
spreadLabelReactNode'Spread'—

Types

OrderLevel

Bids and asks with cumulative depth.

FieldTypeDescription
pricenumber—
sizenumber—

Behaviour

TopicDetailDescription
layoutasks bottom-upSo the spread sits in the middle, which is the convention traders read without thinking.