跳到正文
DEV Community· Savva Sicevs·· 33 分鐘前AI 評分41

我向六款 AI 工具詢問 React 訂單簿元件,最多人推薦的版本最後更新於 2023 年

I asked six AI tools for a React order book. The top pick was last updated in 2023.

AI 導讀

作者向六款支援網頁搜尋的 AI 工具詢問 React 訂單簿元件,最多人推薦的程式碼庫最後更新於 2023 年 7 月。作者將自己的訂單簿元件獨立放到程式碼庫,並以 shadcn registry item 供用戶加入 React 和 Tailwind 專案,原始碼可自行修改。元件支援切換價格分組、顯示深度條,並可查看指定價格以內的總數量和價值。

正文

I build components for trading and finance screens. I asked six AI tools with web search for a good React order book component. Most of the answers pointed at the same few repos. The one they cited most was last updated in July 2023.

Those repos did the job back then. But if you're building an exchange or a perps front end now, you probably want something that drops into a shadcn and Tailwind project and that you can change.

So I put the order book from my library on its own repo. Here's what I think an order book has to do, and how this one does it.

What an order book has to do

It has to stay readable when the market is busy. So prices group by the market's tick, and you can switch the grouping.

It has to show where the size sits. Each level gets a depth bar, so you see the walls without reading every number.

It has to answer the question a trader actually has. Point at a level and it tells you the total size and value up to that price. That's the number you want before you place a big order.

And the numbers can't jump. Every figure is set in tabular numerals, so the columns stay still while prices tick. It sounds small, but it's the first thing that makes a book feel cheap when it's wrong.

Install

It's a shadcn registry item, so in a React project with Tailwind:

npx shadcn@latest add @ssych/order-book

The source lands in your project. It's yours to change.

Use

<OrderBook symbol="BTC-USD" unit="BTC" bids={bids} asks={asks} tick={0.5} feed={false} />

bids and asks are arrays of { price, size }. feed runs a demo feed for the docs, so turn it off when you pass live levels from your exchange or websocket.

What it doesn't do

It doesn't virtualise thousands of rows. It's sized for the levels one screen shows. If you need a deep ladder you scroll through, a data grid fits better.

The parts around it

An order book rarely sits alone. Next to it you usually want a depth chart, a time and sales tape, an order ticket and a positions table. For perps I think the ticket should show the liquidation price before you confirm. Finding it out after the click is one of the worst things a trading UI can do to someone.

They're all free and MIT here: https://ssych.com/library/s/perps-dex

The repo: https://github.com/savvasicevs/react-order-book

If you've built an exchange UI, I'd really like to hear what you'd add.

來源:DEV Community · dev.to