A high-performance centralized cryptocurrency exchange implementation in Rust, featuring spot and margin trading capabilities with real-time market data distribution.
![Screenshot 2025-02-11 at 5 50 06 PM](https://private-user-images.githubusercontent.com/102040059/411968627-6b31f943-ba80-435c-b7f7-7f06b9d34259.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzk1MDk2OTQsIm5iZiI6MTczOTUwOTM5NCwicGF0aCI6Ii8xMDIwNDAwNTkvNDExOTY4NjI3LTZiMzFmOTQzLWJhODAtNDM1Yy1iN2Y3LTdmMDZiOWQzNDI1OS5wbmc_WC1BbXotQWxnb3JpdGhtPUFXUzQtSE1BQy1TSEEyNTYmWC1BbXotQ3JlZGVudGlhbD1BS0lBVkNPRFlMU0E1M1BRSzRaQSUyRjIwMjUwMjE0JTJGdXMtZWFzdC0xJTJGczMlMkZhd3M0X3JlcXVlc3QmWC1BbXotRGF0ZT0yMDI1MDIxNFQwNTAzMTRaJlgtQW16LUV4cGlyZXM9MzAwJlgtQW16LVNpZ25hdHVyZT1jODgzYjUyMGEwMDMxNjVlYTkwNGFkODg1NzdjNTIxYTBiM2MwOWUxYzg0YWRjNTQwMmU4MTAxYWFiODE3YWVlJlgtQW16LVNpZ25lZEhlYWRlcnM9aG9zdCJ9.fOl-HAaB2rvO9QIJtx-C3Fi_0zHt15Un3bNVViOYA7o)
The project consists of three main components:
-
HTTP Server (
http-server/
):- RESTful API endpoints for order management
- Built with Axum framework
- Redis-based communication with the order book manager
-
Orderbook Manager (
orderbook-manager/
):- Core trading engine implementation
- Real-time order matching
- Position and PnL management
- Price service for mark and index prices
- Market depth maintenance
-
WebSocket Server (
websocket-server/
):- Real-time market data streaming
- Room-based subscription system
- Redis pub/sub integration
- Client connection management
-
Wallet Manager (
wallet-manager/
):- Wallet management
- Balance tracking
- Transaction history
- Onramp and offramp support
-
Trading Capabilities:
- Spot trading with limit orders
- Margin trading with up to 10x leverage
- Real-time order matching
- Position tracking and PnL monitoring
-
Market Data:
- Real-time orderbook depth
- Trade execution broadcasts
- Price updates (mark, index, last)
- WebSocket streaming
-
Risk Management:
- Margin requirement validation
- Position monitoring
- Liquidation price calculation
- Balance checks
docker compose up --build -d
yes that's it!
- Balance validation
- Order matching
- Real-time execution
- Balance updates
- WebSocket notifications
- Margin requirement checks
- Position creation/update
- PnL monitoring
- Liquidation price tracking
- Real-time position updates
- Priority queue-based orderbooks
- Position tracking system
- Real-time price service
- WebSocket subscription management
- Redis for inter-service messaging
- WebSocket for real-time updates
- REST API for order management
- Continuous PnL calculation
- Position risk assessment
- Balance tracking
- Market data broadcasting
Built with 🦀 and ❤️