Order Book
Live bids and asks with depth bars, price grouping and a spread row, for a trading screen.
Attributes
| Name | Type | Default | Description |
|---|---|---|---|
bids | readonly OrderBookLevelInput[] | [] | The buy side, best first or in any order: a snapshot that replaces the bids. |
asks | readonly OrderBookLevelInput[] | [] | The sell side, in any order: a snapshot that replaces the asks. |
layout | 'stacked' | 'split' | stacked | Asks over bids with the spread between (stacked), or bids and asks side by side (split). |
depth | number | 10 | Levels drawn on each side. |
group | number | 0 | The price step levels are merged into: bids round down to it, asks round up. 0 shows every price. |
groups | string[] | [] | Price steps the reader may pick from in the header, as a ; list ("0.01;0.1;1;10"). |
base | string | — | The traded asset, for the size header: "Size (BTC)". |
quote | string | — | The pricing asset, for the price header: "Price (USD)". |
price-precision | number | undefined | — | Fraction digits of prices. Without it: the group step's, else the most the data has. |
size-precision | number | 4 | Fraction digits of sizes and totals. |
last-price | number | undefined | — | The last trade price, shown in the spread row with an arrow against the previous one. Without it: the mid price. |
own-prices | string[] | [] | Prices the user has orders at, as a ; list: each gets a dot. |
label | string | — | The heading and accessible name. |
loading | boolean | false | Shows a spinner and "Waiting for the book…" while the book is empty. |
locale | string | — | The locale numbers are formatted in. Without it: the nearest lang. |
Events
| Name | Type | Description |
|---|---|---|
price-select | CustomEvent<{ side: 'bid' | 'ask'; price: number; size: number; total: number }> | Fired when a row is clicked or Enter is pressed on it. Does not bubble. |
group-change | CustomEvent<{ group: number }> | Fired when the reader picks a price step in the header. Does not bubble. |
CSS parts
Shadow DOM styling hooks used with ::part(name). Prefer CSS custom properties when they cover the change.
| Name | Description |
|---|---|
header | The heading and the price grouping picker. |
spread | The row between the two sides: the mid or last price and the spread. |
row | Every price level row. |
empty | The message shown while the book is empty or loading. |
CSS custom properties
Grouped by semantic target and state from --c2-<component>__<target>__<state>--<property>. Click a group to collapse it; click a name to copy it.
| Name | Type | Default | Description |
|---|---|---|---|
--c2-order-book--border | border | 1px solid #e4e4e7 | |
--c2-order-book--border-radius | border-radius | 8px | |
--c2-order-book--background | color | #ffffff | |
--c2-order-book--color | color | #18181b | |
--c2-order-book--font-size | font-size | 12px | |
--c2-order-book--font-family | font-family | inherit | |
--c2-order-book__divider--border | border | 1px solid #e4e4e7 | The lines under the header, around the spread row and between the sides. |
--c2-order-book__header--display | display | flex | none hides the heading and the grouping picker. |
--c2-order-book__header--padding | padding | 8px 12px | |
--c2-order-book__title--font-size | font-size | 14px | |
--c2-order-book__title--font-weight | font-weight | 600 | |
--c2-order-book__grouping--width | pixel | 96px | Width of the price grouping picker. |
--c2-order-book__column-header--color | color | #71717a | |
--c2-order-book__row--height | pixel | 20px | |
--c2-order-book__row--padding-inline | pixel | 12px | |
--c2-order-book__row__hover--background | color | #f4f4f5 | |
--c2-order-book__row__focus--outline | outline | 2px solid rgba(2, 101, 220, 0.4) | |
--c2-order-book__bid--color | color | light-dark(#166534, #4ade80) | Bid prices; the bid bars and flashes are mixed from it. The light and dark values keep 4.5:1 on the bars. |
--c2-order-book__ask--color | color | light-dark(#b91c1c, #f87171) | Ask prices; the ask bars and flashes are mixed from it. The light and dark values keep 4.5:1 on the bars. |
--c2-order-book__bid-bar--background | color | color-mix(in srgb, var(--c2-order-book__bid--color, light-dark(#166534, #4ade80)) 14%, transparent) | The depth bars of the bids. |
--c2-order-book__ask-bar--background | color | color-mix(in srgb, var(--c2-order-book__ask--color, light-dark(#b91c1c, #f87171)) 14%, transparent) | The depth bars of the asks. |
--c2-order-book__flash--duration | duration | 600ms | |
--c2-order-book__flash__up--background | color | color-mix(in srgb, var(--c2-order-book__bid--color, light-dark(#166534, #4ade80)) 20%, transparent) | A level whose size grew. |
--c2-order-book__flash__down--background | color | color-mix(in srgb, var(--c2-order-book__ask--color, light-dark(#b91c1c, #f87171)) 20%, transparent) | A level whose size shrank. |
--c2-order-book__own--size | pixel | 4px | The dot after a price the user has an order at. |
--c2-order-book__spread--background | color | #fafafa | |
--c2-order-book__spread--padding | padding | 6px 12px | |
--c2-order-book__spread__price--font-size | font-size | 16px | |
--c2-order-book__spread__price--font-weight | font-weight | 600 | |
--c2-order-book__spread__label--color | color | #71717a | |
--c2-order-book__empty--min-height | pixel | 160px | |
--c2-order-book__empty--color | color | #71717a | |
Text and languages
The text the component shows, in English. It shows another language when the app adds one with addTranslations, under order-book, and the nearest lang asks for it; any message not translated stays in English. {0}, {1}… stand for the values a message carries. Languages guide.
| Key | English | Values |
|---|---|---|
label | Order book | — |
asks | Asks | — |
bids | Bids | — |
price | Price | — |
priceIn | Price ({0}) | {0} quote |
size | Size | — |
sizeIn | Size ({0}) | {0} base |
total | Total | — |
bid | Bid | — |
ask | Ask | — |
grouping | Price grouping | — |
spread | Spread {0} ({1}) | {0} value {1} percent |
mid | Mid price | — |
last | Last price | — |
own | your order | — |
loading | Waiting for the book… | — |
empty | No orders | — |