Skip to content

TUI: make order book depth levels interactive (toggle preset + scroll through levels) #26

@llcro

Description

@llcro

Summary

Add keybindings in the Market detail view so the user can (1) toggle the fetched order-book depth between presets, and (2) walk the selection up and down through rendered levels to inspect cumulative liquidity at specific price points. Today the book is fixed at depth=20 with no interactive way to see deeper levels or compare liquidity across levels.

Current behaviour

  • crates/cdcx-tui/src/tabs/market.rs:160 hardcodes {"depth": "20"} on the REST public/get-book fetch.
  • crates/cdcx-tui/src/widgets/detail_view.rs:97 (draw_book) renders all bids/asks it has, with no selection cursor.
  • User can see only top 20 bids + 20 asks. No way to:
    • Zoom out to see top 50 / 150 for whale/sweep analysis.
    • Zoom in to top 5 for tight-spread instruments.
    • Scroll through levels to read cumulative depth at a specific price.

Proposed feature (two complementary pieces)

Piece 1 — Depth preset toggle

Keybinding (suggested: D or [/] pair) cycles the fetched depth through presets: 5 / 10 / 20 / 50 / 150.

  • Preset is persisted in AppState so it survives instrument switches during the session.
  • On change: re-fetch via public/get-book with new depth, re-subscribe to book.{instrument}.{depth} if the WS channel supports depth suffixes (verify — some exchanges require book.symbol.N while others push a fixed depth).
  • Footer hotkey hint line gets a D:depth(50) indicator showing the current preset.

Piece 2 — Level navigation

Selection cursor that the user moves with / or j/k:

  • Cursor lands on a specific bid or ask row.
  • Highlighted row shows: price, level qty, cumulative qty from top of book to this level, cumulative notional USD, and distance from mid in bps/%.
  • Pressing Esc / switching view clears the selection.
  • Optional: pressing Enter on a selected level pre-fills the place-order modal with that price.

Piece 2 on its own is independently useful even without Piece 1 — scrolling through 20 levels helps analyse thin books. But they pair naturally: toggle to 150, scroll to find the liquidity wall.

Implementation notes

  • Piece 1 is mostly plumbing: add book_depth: usize to MarketTab (or AppState if we want it persisted via the tui.toml workflow from TUI: watchlist add/remove does not persist to ~/.config/cdcx/tui.toml #23), change the fetch params, add a key handler, update the status line.
  • Piece 2 needs:
    • A book_cursor: Option<usize> on MarketTab, plus a convention for index-into-concatenated-asks-then-bids.
    • A detail pane under/beside the book showing the cumulative stats for the selected level.
    • Care in draw_book to style the selected row without breaking the existing depth-bar rendering (detail_view.rs:194-251).

Both pieces are agent-parity opportunities — a matching MCP tool should be able to query the book at a given depth (already possible via cdcx market book) so agents can reach the same insight the TUI now surfaces.

Scope

One issue covering both pieces; the PR can land them separately. Piece 1 first is the lowest-friction starting point.

Related

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions