Skip to content

AkashJana18/perplab

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PerpLab

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.

Features

Exchange Engine

  • Central Limit Order Book (CLOB)
  • Price-time priority matching
  • Limit orders
  • Market orders
  • Partial fills
  • Order cancellation
  • Long and short positions

Risk Engine

  • Margin management
  • Initial margin checks
  • Maintenance margin checks
  • Liquidation engine
  • Insurance fund

Perpetual Futures Mechanics

  • Funding rate calculations
  • Mark price tracking
  • Index price tracking
  • Realized and unrealized PnL
  • Position management

Market Simulation

  • Autonomous trading bots
  • Market making strategies
  • Momentum strategies
  • Mean reversion strategies
  • Scalping strategies
  • Funding arbitrage strategies
  • Liquidation hunter strategies
  • Whale simulation

Live Market Data

  • Real-time SOL price feed
  • WebSocket updates
  • Live orderbook updates
  • Live trade stream
  • Candlestick chart support

Developer Tooling

  • Exchange state inspector
  • Bot activity monitor
  • Liquidation debugging
  • Funding controls
  • Market simulation controls

Tech Stack

Backend

  • Rust
  • Axum
  • Tokio
  • Serde
  • UUID

Frontend

  • Next.js
  • TypeScript
  • Tailwind CSS
  • shadcn/ui
  • TanStack Query
  • Zustand
  • Lightweight Charts

Architecture

Filecoin Client Ecosystem-2026-05-31-182720

Why PerpLab?

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.

Running Locally

Backend

cargo run 

Frontend

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.

About

A mini Central Limit Order Book (CLOB) based perpetual futures exchange built in Rust.

Topics

Resources

Stars

Watchers

Forks

Contributors

Languages