A mini Central Limit Order Book (CLOB) based perpetual futures exchange built in Rust.
PerpLab was created to understand the core infrastructure behind modern perpetual exchanges such as Phoenix, Drift, Hyperliquid, and other orderbook-driven trading systems. Rather than focusing only on trading interfaces, PerpLab focuses on the exchange engine itself: matching orders, managing positions, calculating funding, enforcing margin requirements, and processing liquidations.
- Central Limit Order Book (CLOB)
- Price-time priority matching
- Limit orders
- Market orders
- Partial fills
- Order cancellation
- Long and short positions
- Margin management
- Initial margin checks
- Maintenance margin checks
- Liquidation engine
- Insurance fund
- Funding rate calculations
- Mark price tracking
- Index price tracking
- Realized and unrealized PnL
- Position management
- Autonomous trading bots
- Market making strategies
- Momentum strategies
- Mean reversion strategies
- Scalping strategies
- Funding arbitrage strategies
- Liquidation hunter strategies
- Whale simulation
- Real-time SOL price feed
- WebSocket updates
- Live orderbook updates
- Live trade stream
- Candlestick chart support
- Exchange state inspector
- Bot activity monitor
- Liquidation debugging
- Funding controls
- Market simulation controls
- Rust
- Axum
- Tokio
- Serde
- UUID
- Next.js
- TypeScript
- Tailwind CSS
- shadcn/ui
- TanStack Query
- Zustand
- Lightweight Charts
Most traders interact with a simple Buy or Sell button.
Behind that button exists a complex system responsible for:
- Matching orders fairly
- Managing leverage
- Tracking collateral
- Calculating funding payments
- Handling liquidations
- Protecting exchange solvency
PerpLab was built to explore and implement those systems from first principles.
cargo run npm install npm run dev Disclaimer: PerpLab is an educational project built to explore perpetual futures exchange architecture and trading infrastructure. It is not production-ready and should not be used to manage real funds.