Sheshivardhan
CEX trading terminal
← Projects

CEX

A centralised exchange, matched in Rust.

CEX is a spot trading exchange built end to end: a Rust matching engine with price-time priority, an Axum REST and WebSocket API, Postgres persistence with JWT authentication, and a browser trading terminal with a live order book, tape and candlestick chart. Orders live in memory, fills are emitted as events, and the whole path is benchmarked.

github.com/nsvoriginals/cex ↗

Role
Matching engine, API and terminal
Stack
Rust · Tokio · Axum · SQLx
Data
Postgres · WebSocket event stream
Year
2026 · source available

The matching engine

The engine is the centre of the system. Orders are stored in two sorted sides of the book, and incoming orders match by price first, then time. Every fill produces an execution report, updates both orders and removes filled levels. Five order types — market, limit, IOC, FOK and post-only — share the same matcher, so the API layer never has to reason about book state directly.

The API and persistence

Axum exposes the exchange over REST and WebSockets. Registration and login use Argon2 password hashes and JWT sessions; authenticated handlers place and cancel orders, while public handlers serve markets, tickers, the book and recent trades. SQLx talks to Postgres with compile-time-checked queries and migrations, and the service ships with a Dockerfile and environment-based config so the same binary runs locally and in a container.

The terminal

An exchange is only as good as the screen traders actually use. The front end is deliberately dependency-light: plain ES modules, a shared API/WebSocket client, and Chart.js for candles. It keeps the order book, tape and ticker in sync from one socket, lets you switch symbols and timeframes without a reload, and puts the order ticket next to the depth book so price, size and spread are always in view.

drop terminal.png here · /assets/img/cex/terminal.png
CEX trading terminal with order book and chart

The terminal. Symbol, depth, tape, candles and the order ticket on one screen.

drop orderbook.png here · /assets/img/cex/orderbook.png
CEX live order book

Live depth. Bids and asks update from the WebSocket stream, with spread and last price in the header.

drop auth.png here · /assets/img/cex/auth.png
CEX sign-in screen

Sessions. Argon2-hashed passwords, JWT sessions and a terminal that refuses to render without a valid token.

What I focused on