Longbridge Pro Trading Terminal Example
Live Demo
Overview
A Longbridge-styled desktop trading terminal built with vgui-shadcn components and a hand-drawn canvas chart. The layout is the classic three-pane broker workstation: a searchable, live-ticking watchlist on the left; a symbol header, stat strip, timeframe-switchable price chart, and Positions/Orders tables in the center; and a market-order ticket plus account summary on the right.
Prices are a deterministic random walk over eight US and Hong Kong instruments. Market orders fill instantly at the live price, cash moves, and opposing positions are netted with realized P/L (a buy closes a short before extending a long, and vice versa). Fills surface as toasts. There is no network or brokerage backend — the whole simulator is in market.rs.
Key Concepts
- Single brokerage store. One
create_store(MarketState)owns instruments, positions, orders, cash, and the PRNG; every read is reactive, andplace_ordermutates cash, order history, and netting in one transaction. - Live feed with
use_interval. Acreate_memomaps the live toggle to a tick interval (1200ms running,0paused); the interval callsset_market.update(cx, |s| s.tick()). - Canvas chart.
chart.rsdraws grid, area, line, and a last-price tag to a fixed-sizeContext2D. Timeframe tabs (1D/1W/ALL) only change how many history points are shown. - Long/short netting.
apply_fillfirst reduces an opposing position, booking realized P/L, then opens or extends a position in the order’s direction. - Toast stack in a store.
Toastis notPartialEq, so theVec<Toast>lives in a Clone-only store rather than a signal; a separate id signal supplies unique toast keys. - Runtime colors.
css!colors are compile-time, so up/down tints (red up, green down — the Asian-market convention) use atinted(text, hex)helper returning agpui::div().text_color(..). - Module split.
market.rs(simulation + formatting),chart.rs(canvas rendering),main.rs(state wiring and views).
Running
Native:
cargo run -p vgui-longbridge-pro
Web (WASM):
cargo build --target wasm32-unknown-unknown -p vgui-longbridge-pro --release
wasm-bindgen --target web --out-dir examples/longbridge-pro/dist \
--no-typescript target/wasm32-unknown-unknown/release/longbridge-pro.wasm
python3 scripts/serve_plain.py 8080 examples/longbridge-pro
Source Code
See examples/longbridge-pro/src/main.rs, src/market.rs, and src/chart.rs.