Live Simulation Active

Ultra-Low Latency.
Production-Grade
Design.

A high-fidelity electronic trading platform featuring a real-time CLOB matching engine, nanosecond latency profiling, strategy execution framework, and live monitoring dashboards — built to professional HFT infrastructure standards.

mini-hft · AXTI ○ connecting…
AXTI
NASDAQ · Central Limit Order Book
—
fetching…
Yahoo Finance
ORDERSSIZEPRICE
SPRD 0.02 MID — SEQ 1
EXECUTION TAPE
p50
1.6µs
p99
5.7µs
p999
26.3µs
1.6µs
C++ Frame p50 Latency
542K
Orders / Second (Native)
M8
FPGA Scaffold Complete
O(1)
Cancel Lookup via Stable Pointers
100+
Engine + Conformance Tests
01 System Design

Hot path. Cold path.
Clean separation.

Every design decision mirrors patterns used in production exchange infrastructure. The matching engine never touches I/O — events fan out through a bounded in-process bus at nanosecond cost to persistence and WebSocket consumers.

CLIENT TIER
Browser / Strategy Bots
REST POST /orders · WebSocket /api/v1/market-data/ws · Next.js Live Dashboard
COLD PATH
HTTP / WebSocket frames
API GATEWAY
FastAPI
OrderRouter · MarketDataRouter · MetricsRouter · WS Manager
WARM
SERVICE LAYER
Business Logic
OrderService · BookStreamService · TradeTapeService · MetricsService
WARM
MARKET DATA
GBM Publisher
Geometric Brownian Motion feed · TICKER events · Async background task
WARM
synchronous call — no await, no I/O
HOT PATH
MatchingEngine (Python HAL → C++20 pybind11 native)
Price-time priority CLOB · No I/O, no async, no logging · Pure computation · submit_order(Order) → MatchResult · O(log P) insert · O(1) cancel via stable node pointers
HOT PATH ~1.6µs frame p50 542K ops/sec
queue.put_nowait() — ~100ns, never blocks engine
EVENT BUS
asyncio.Queue
Bounded per event type · Drop-counted · Never blocks matching · ~100ns put cost
IN-PROCESS
WS BROADCASTER
WebSocket Fan-out
BOOK_SNAPSHOT/DELTA · TRADE · TICKER · LATENCY_SNAPSHOT · STRATEGY_METRICS
COLD
PERSISTENCE
AsyncDatabaseWriter
Batched PostgreSQL via asyncpg · Off the hot path · Retry + drop metrics
COLD
02 Core Components

Every layer
built for speed.

Six independently testable components, each with a defined hot/cold boundary and a replaceable interface for Python, C++, FPGA, or cloud-native upgrade paths.

01
Matching Engine
Central Limit Order Book with price-time-priority FIFO. Python and C++/pybind11 backends behind a swappable binary HAL. O(log P) insertion, O(1) cancel via stable intrusive order-node pointers.
CLOB C++20 pybind11 FPGA-ready GTC/IOC/FOK
02
Order Book
10-level bid/ask depth with sequence-aware BOOK_SNAPSHOT/DELTA protocol. Clients detect sequence gaps and request a fresh snapshot — the exchange-standard recovery model used by NASDAQ, CME, and NYSE.
SortedDict FIFO levels Delta encoding Seq. recovery
03
Strategy Runtime
Event-driven executor with kill-switch, inventory-adjusted PnL, cancel/replace quoting on meaningful market moves, and deterministic replay for backtesting and incident reconstruction.
Risk-gated Position limits PnL tracking Replay Kill switch
04
Market Data Infrastructure
GBM price feed generating realistic tick sequences. WebSocket-pushed TICKER, TRADE, and BOOK events with sequence numbers. Full book recovery on reconnect. Multi-symbol support.
GBM WebSocket Multi-symbol Heartbeat
05
Async Persistence
Batched PostgreSQL writes via SQLAlchemy Core/asyncpg. Completely off the matching hot path. Metrics track consumed, written, retry, and drop rates for full operational visibility.
PostgreSQL asyncpg Batched writes Idempotent
06
Live Dashboard
Next.js frontend with 10-level order book ladder, rolling p50/p99/p999 latency chart (Recharts), strategy launcher with PnL, trade tape, and system health indicator.
Next.js 15 Recharts Tailwind WebSocket
03 Benchmark Results — May 2026

The numbers
that matter in HFT.

5,000 rounds per scenario on Windows/MSVC. The frame path separates native matching cost from service projection overhead — exactly the view needed before committing to a slab allocator or binary transport layer.

Path / Backend Scenario p50 p99 p999 Ops/sec Relative
Frame / C++ Resting insert 1.6µs 5.7µs 26.3µs 542,788
fastest
Frame / C++ Single fill 1.5µs 6.5µs 25.4µs 583,512
fastest
Frame / C++ 10-level sweep 3.2µs 8.1µs 13.7µs 282,892
×2
Object / C++ Resting insert 19.2µs 35.7µs 73.0µs 49,870
×11
Object / Python Single fill 9.2µs 12.2µs 23.1µs 107,345
×5.5
Object / Python Resting insert 231.3µs 656.6µs 4,450µs 3,492
baseline
04 Design Principles

The hot-path
contract.

The engine boundary enforces a zero-I/O invariant. No FastAPI, no SQLAlchemy, no asyncio — pure computation behind a single protocol that Python, C++, and FPGA all implement identically.

engine/hal/abstract.py — replaceable matching contract
# Python, C++, and FPGA all implement this.
# OrderService never sees a concrete engine.
class MatchingHAL(Protocol):
    def submit_order(
        self, order: Order
    ) -> MatchResult: ...

    def cancel_order(
        self, order_id: str
    ) -> Order | None: ...

    def get_snapshot(
        self, symbol: str
    ) -> BookSnapshot | None: ...
shared/events.py — non-blocking fan-out
# publish_nowait: ~100ns.
# Never blocks the matching hot path.
# DB and WS push drain independently.
class EventBus:
    def publish_nowait(
        self, event: DomainEvent
    ) -> None:
        for q in self._queues[event.type]:
            try:
                q.put_nowait(event)
            except asyncio.QueueFull:
                # metric, not an error
                self.drop_count += 1
05 Implementation Roadmap

Eight milestones.
Production discipline.

Each milestone adds one major capability without breaking existing test coverage or API contracts.

M1
Core Matching Engine + Tests
Price-time priority CLOB, full order lifecycle, 30+ unit tests for fill semantics, cancel, and TIF variants (GTC, IOC, FOK, Market).
Done
M2
FastAPI Backend + WebSocket
Async API gateway with EventBus fan-out, REST order management, and full WebSocket protocol with 10+ message types.
Done
M3
Market Data Feed (GBM)
Geometric Brownian Motion price generator, async background publisher, TICKER events, multi-symbol support (AAPL, TSLA, MSFT, AMZN, NVDA).
Done
M4
PostgreSQL Async Persistence
Batched asyncpg writer with drop counters, idempotent retry, and health metrics — completely off the matching hot path.
Done
M5
Strategy Sandbox + Executor
Risk-gated OrderGateway, kill-switch, inventory-adjusted PnL, SimpleMarketMaker with cancel/replace quoting, deterministic replay.
Done
M6
Next.js Live Dashboard
10-level order book ladder, rolling p50/p99/p999 latency chart, strategy launcher with PnL readout, trade tape, system health monitoring.
Done
M7
C++20 CLOB Engine + Binary HAL
C++20 matching core with pybind11 bindings, 64-byte ORDER_FRAME wire ABI, parity tests against Python engine, full benchmark suite with p50/p99/p999/throughput.
Done
M8
FPGA HAL Scaffold
PCIe DMA ring architecture, XRT integration design, BRAM-backed price-level arrays, parallel comparators, target <200ns order-to-trade.
Scaffold
06 Technology Stack

Chosen for latency.
Built to replace.

Each layer sits in the right position on the hot/cold spectrum with a seam for production upgrade to FPGA or cloud-native infrastructure.

[01]
C++20 / Python 3.11
HAL-switched matching core. Zero I/O. Swappable without touching service code.
[02]
FastAPI
Async-native ASGI. Auto-docs. Pydantic validation at API boundaries.
[03]
WebSockets
Zero round-trip push. Sequence-aware SNAPSHOT/DELTA recovery protocol.
[04]
PostgreSQL + asyncpg
Batched async writes. Append-only trade log. Completely off the hot path.
[05]
Next.js 15
App Router. Tailwind CSS. Recharts for real-time latency visualization.
[06]
Docker Compose
One-command dev parity. API + PostgreSQL + Dashboard wired together.
[07]
pybind11
Zero-overhead Python ↔ C++ bridge. No FFI overhead on the native path.
[08]
FPGA / XRT (M8)
PCIe DMA ring. BRAM price arrays. Parallel comparators. <200ns target.