MCPcopy Create free account
hub / github.com/DegenSugarBoo/OpenBook

github.com/DegenSugarBoo/OpenBook @main

Chat with this repo
repository ↗ · DeepWiki ↗ · + Follow
285 symbols 660 edges 10 files ⚖ MIT 14 documented · 5% ● updated 5d ago★ 208

Browse by type

⨍ Functions 232◇ Types & classes 53
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

OpenBook: the order-flow terminal for every venue

OpenBook: a real-time order book viewer for crypto and RWA perps

OpenBook is a native desktop app, written in pure Rust, for reading market microstructure live on Binance (USD-M, COIN-M, spot), Bybit (linear, inverse, spot) and Hyperliquid (including trade.xyz RWA perps), or on all of them combined.

  • It streams depth, trades, liquidations, mark price and funding.
  • It draws a Bookmap-style liquidity heatmap that scrolls and zooms at your display's refresh rate.
  • Around the heatmap sit a painted price ladder, a sweep-grouped tape and order-flow analytics.

It needs no GPU shaders or web stack. The whole UI is egui meshes and one texture, so it runs on any machine with a window system: macOS, Linux and Windows.

OpenBook live on the combined BTC book (Binance, Bybit, Hyperliquid): stats strip, constituents, depth heatmap with trade bubbles, venue-stacked ladder, sweep-grouped tape, Flow pane and market impact

Highlights

  • Heatmap
  • Speed: history lives in a ring texture on a fixed price grid. Each 100 ms book update buckets one column and uploads a 1-pixel strip. Zooming and panning only move texture coordinates. A frame costs 0.02 ms where the old renderer took 7 ms (see benchmarks).
  • Motion: zoom and pan ease and stay anchored under the cursor. Scrolling is continuous and runs on an estimate of the exchange clock.
  • Colour: the colour scale is percentile-based (p99.5 ceiling, log curve around the median), so one huge wall doesn't wash out everything else. A contrast slider sets the curve.
  • Overlays:
    • trade bubbles sized by notional against the visible p90, with same-side prints merged;
    • best bid/ask step lines;
    • a live book profile;
    • liquidation markers;
    • market impact on the price axis: how far a market order of your size would sweep.
  • Price ladder
  • Painted, not built from widgets. Rows fill the pane and group by 1 to 250 ticks.
  • Bars ease; levels flash when they grow or shrink; walls are outlined; cumulative depth is shaded behind the bars.
  • Hovering a level shows the size, average fill and slippage of sweeping to it.
  • Sweep-grouped tape
  • Prints from one taker order (same side and timestamp) collapse into one row showing VWAP and how many levels it walked.
  • "Big" and "whale" thresholds adapt to the symbol (p90 and p99 of recent rows).
  • Rows are virtualised.
  • Flow pane (replaces the old Fill:Kill ratio)
  • Every taker burst is classified against the book before and after it:
    • Absorbed: liquidity refilled.
    • Sweep: the book was eaten.
    • Vacuum: liquidity was pulled ahead of the order.
  • Shows a fill-share KPI, a CVD chart with a price overlay, and a sweep timeline.
  • Stats strip
  • mid, with a tick flash;
  • spread in ticks and bps;
  • microprice − mid;
  • ±10 bp book imbalance;
  • CVD over 1 minute, with a sparkline;
  • real trades per second (counting every fill, not every aggregate) and buy share;
  • normalised OFI;
  • funding rate with countdown and mark − index basis;
  • open interest with its 5-minute change;
  • liquidations;
  • feed latency, p50 and p95.
  • Feed
  • One select-loop task per connection.
  • A tested depth-sync state machine handles bridging the snapshot, gaps, duplicates and out-of-order updates. A gap resyncs in place without reconnecting.
  • Reconnects use jittered backoff; time is resynced every minute.
  • Hyperliquid's l2Book socket channel only pushes every ~11 s, so its depth is polled over REST (every 0.5 s, spaced out to stay within half the per-IP rate limit when several markets are open, with backoff on errors). The bbo channel keeps the top of the book current between polls.
  • Hostnames go to the system resolver. If it returns a sinkhole address, or connecting to its answer fails, that host switches to DNS-over-HTTPS (Cloudflare 1.1.1.1). OPENBOOK_DOH=off turns that off and OPENBOOK_DOH=force always uses it.
  • REST weight is about 7 per minute in steady state.
  • The UI is woken by data, not by polling.
  • Workspace
  • Dockable panes (egui_tiles) and layout profiles.
  • Market picker: venue tabs (Tab / Shift+Tab), fuzzy search with the match highlighted, recent markets, and a virtualised list of every market.
    • Lookbacks of 5m, 15m, 1h, 4h and 24h for the change and volume columns, plus Top gainers / Top losers / Most active and sortable headers.
    • Under 24 h, change comes from minute samples recorded locally from the ticker feeds (every venue's catalog runs from launch), so a window shows "~" until it is fully covered. Volume under 24 h is estimated from the rolling 24 h figure.
    • Each row has a sparkline of the lookback; combined rows show the venues they sum.
  • Several markets at once: pin any pane to a market from the Markets ▾ menu and it stays there while the rest follow the picker. OPENBOOK_MARKETS=btcusdt,ALL:BTC,HL:xyz:TSLA opens a list at startup (no prefix means Binance USD-M).
  • Combined book (ALL in the venue menu)
  • BTC sums the BTC perps on Binance, Bybit and Hyperliquid; BTC+SPOT adds the spot books. Books are bucketed onto the coarsest venue tick and summed, and trades, liquidations and open interest are merged.
  • A strip under the stats lists the venue markets in the book, each with its feed state, share of depth near mid and price basis.
  • Cumulative and segregated at once: the heatmap shows total liquidity, while the ladder bars and the book profile are split by venue colour. Hovering a ladder row gives each venue's size and share.
  • Venues can disagree on price by a few bps; the ladder then reads "crossed" in amber instead of hiding the gap.
  • Hyperliquid serves 20 levels a side and has no server-time endpoint, so its depth is shallow and has no latency figure; FEED shows the slowest venue that reports one.
  • Each venue's own best bid and ask is marked on the ladder with a notch in its colour.
  • Venue layer
  • Each venue adapter turns its own wire format and sync rules into one set of normalized events (book snapshot and delta, trade, liquidation, mark, open interest, clock).
  • Instruments carry tick, lot and contract size, so sizes are always base units and notionals USD.
  • The Binance adapter is tested by replaying recorded live traffic, including a check that the rebuilt book matches a later REST snapshot.

Getting started

You need Rust. The repository pins its toolchain in rust-toolchain.toml.

git clone https://github.com/DegenSugarBoo/OpenBook.git
cd OpenBook
cargo run --release

It connects to btcusdt on startup. Use the symbol picker in the header to switch symbols.

On Linux you need the usual windowing libraries (X11 or Wayland, plus libxkbcommon). Any GPU, or software rendering, that wgpu supports will do.

Controls

Heatmap

Input Action
Wheel Time zoom, anchored at the cursor
⌘/⇧ + wheel, or wheel on the price axis Price zoom
Drag Pan; dragging back to the right edge snaps to live
Drag an axis Stretch that axis
Double-click or L Back to live
Space Pause or resume
= / - Time zoom in / out
[ / ] Lower / raise contrast
T B I K Toggle trades, BBO, impact, book profile

The ⓘ icon in the heatmap toolbar lists all of these.

Other panes

Pane Controls
Ladder Group buttons choose ticks per row; Σ toggles cumulative depth
Tape Group sweeps toggle; optional minimum $ filter (applied after grouping)
Flow Show or hide Normal bursts; minimum $
Market impact Order size in $ and side; the result is also drawn on the heatmap's price axis
Symbol picker ↑ ↓ to move, Enter to connect, Esc to close

Architecture

src/
├── main.rs            entry point and wiring
├── net/               Binance connectivity
│   ├── session.rs     one select! loop per connection: sockets, resync, timers, backoff
│   ├── depth_sync.rs  pure snapshot/diff bridging state machine (unit-tested)
│   ├── binance.rs     endpoints, typed stream decoding, instruments
│   ├── binance_book.rs USD-M book rules over decoded frames (no I/O, replay-tested)
│   ├── http.rs        shared REST client: snapshot, open interest, time, exchangeInfo
│   └── tickers.rs     symbol catalog and miniTicker feed
├── market.rs          venues, instruments, normalized feed events, the sink into SharedState
├── markets.rs         open markets: one feed and state per (venue, symbol)
├── models.rs          order book, trade and depth history, SharedState, ConnState
├── metrics.rs         CVD, OFI, microprice, band depth, flow, liquidations, latency
├── micro.rs           sweep engine: burst detection and absorbed/sweep/vacuum classification
├── heatmap_ring.rs    ring texture renderer: bucketing, colour scale, strip uploads, mesh
├── workspace.rs       dock tree, pane kinds, layout profile persistence
├── ui.rs              app shell, header, panes, snapshot
└── ui/
    ├── heatmap_view.rs   heatmap interaction, overlays, axes, crosshair
    ├── ladder_view.rs    painted price ladder
    ├── tape_view.rs      sweep-grouped time and sales
    ├── flow_view.rs      sweep regimes, CVD chart, sweep timeline
    ├── stats_bar.rs      metric chips
    └── frame_probe.rs    frame timing, snapshot and recording dev aids

Data flow.

  1. Network tasks on a small shared tokio runtime update SharedState behind a mutex.
  2. They wake the UI at most once every 8 ms.
  3. Each frame, the UI takes a cheap snapshot. Book and trade vectors are shared through Arc and rebuilt only when their epoch changes.
  4. Each pane renders from that snapshot.

The heatmap keeps its own GPU texture and only ever uploads new columns.

More detail in the docs:

Performance

These figures are from an Apple M4 on live BTCUSDT. Full method and numbers are in docs/BENCHMARKS.md.

Frame rate while live 60 fps, one dropped frame in 200 s
Uncapped frame rate ~440 fps live; whole-UI CPU 0.36 ms per frame (headless)
App code per frame 1.0–1.3 ms p50, 1.8–2.6 ms p99 (combined book: 1.3 / 2.9 ms); varies with how busy the market is
Heatmap zoom frame 0.021 ms, was 6.9 ms
Memory ~200 MB, flat; was ~700 MB and growing

Measure it yourself:

OPENBOOK_FRAME_STATS=1 cargo run --release                  # live frame stats every 10 s
cargo test --release heatmap_ring::bench -- --ignored --nocapture   # renderer microbenchmark
cargo test --release frame_bench -- --ignored --nocapture          # whole-UI frame benchmark
OPENBOOK_NO_VSYNC=1 OPENBOOK_FRAME_STATS=1 cargo run --release     # uncapped fps

Screenshots:

OPENBOOK_WINDOW=1000x624 cargo run --release          # window size in points
OPENBOOK_SNAPSHOT=out.ppm OPENBOOK_SNAPSHOT_SECS=20 cargo run --release   # one frame, then quit

Development

cargo test                          # unit tests
cargo test -- --ignored live_       # live tests against Binance (network)
cargo clippy --all-targets -- -D warnings
cargo fmt

CI runs fmt, clippy and tests on Linux, macOS and Windows.

License

MIT

Extension points exported contracts — how you extend this code

browse all types & interfaces →

Core symbols most depended-on inside this repo

browse all functions →

Shape

Function 119
Method 113
Class 46
Enum 6
Interface 1

Languages

Rust100%

Modules by API surface

src/ui.rs75 symbols
src/models.rs43 symbols
src/micro.rs39 symbols
src/workspace.rs34 symbols
tests/unit/ui_tests.rs26 symbols
tests/unit/micro_tests.rs22 symbols
tests/unit/models_tests.rs16 symbols
src/main.rs14 symbols
tests/unit/main_tests.rs13 symbols
tests/unit/workspace_tests.rs3 symbols

For agents

$ claude mcp add OpenBook \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page