You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A production-grade, real-time multi-asset trading platform with live market data, a high-performance matching engine, an AI trading bot, and a Streamlit analytics dashboard.
cd frontend
npm install
npm run dev
# Opens at http://localhost:5173
Analytics
cd analytics
pip install -r requirements.txt
streamlit run app.py
API Reference
Endpoint
Method
Description
/health
GET
System health and uptime
/api/symbols
GET
All supported symbols with live quotes
/api/market-data
GET
Live prices for all 12 assets
/api/market-data/:symbol
GET
Price data for a specific symbol
/api/orderbook?symbol=X
GET
Order book snapshot
/api/trades?symbol=X
GET
Recent trades
/api/candles?symbol=X
GET
OHLCV candle data
/api/orders
POST
Submit a limit or market order
/api/orders/:id
DELETE
Cancel an order
/api/portfolio/:userId
GET
Portfolio summary
/api/orders/:userId
GET
User trade history
/api/stats?symbol=X
GET
Engine statistics
/api/bot/status
GET
AI bot status, P&L, positions, recent trades
/api/bot/start
POST
Start the AI bot
/api/bot/stop
POST
Stop the AI bot
/api/bot/pause
POST
Pause the AI bot
/api/bot/resume
POST
Resume the AI bot
/api/bot/strategies
POST
Update active strategies
/api/bot/trades
GET
AI bot trade log
WebSocket Events (ws://localhost:8080/ws)
Event
Direction
Description
orderbook
Server to Client
Order book updates every 500ms
trade
Server to Client
Trade executions in real time
candle
Server to Client
New OHLCV candles every 5s
market_data
Server to Client
All symbol prices every 2s
order_update
Server to Client
Order status changes
Technical Details
Matching Engine
Price-Time Priority (FIFO):
1. Incoming order checked against opposite book
2. Best price matched first
3. At same price, earliest order fills first
4. Partial fills tracked via remainingQuantity
5. Unfilled limit orders rest in the book
Complexity:
Insert: O(1) amortized
Match: O(k) where k = price levels crossed
Cancel: O(1) via order ID hash map
GBM Price Simulation
S(t) = S0 * exp((mu - sigma^2/2)*t + sigma*sqrt(t)*Z)
Parameters per asset:
mu (drift): 0.0001
sigma (vol): 0.015 to 0.04 depending on asset
dt: per tick
Real CoinGecko prices anchor synthetic prices every 30s.
Micro-updates run every 2s between API calls.
AI Bot Decision Cycle
Every 3 seconds per symbol:
1. Poll latest 100 trades for price/volume history
2. Run all active strategies, get signals with confidence scores
3. Weighted consensus vote (momentum 35%, mean reversion 30%,
breakout 25%, market making 10%)
4. If consensus confidence >= 0.25, execute trade
5. Position sizing via Kelly Criterion (half-Kelly)
6. Check all open trades for stop-loss / take-profit exit
7. Circuit breaker halts all trading at 10% drawdown
WebSocket Batching
Problem: 12 symbols * 20 orders/sec = 240+ events/sec
Solution:
- All events queued in memory buffer
- Every 50ms, buffer flushed and grouped by type
- Single JSON payload sent per client per cycle
- Result: ~20 sends/sec instead of 240+
Bidirectional, lower overhead, native reconnect support
CoinGecko free tier
No API key required, reliable for crypto anchoring
Separate Streamlit service
Decoupled analytics, Python data science ecosystem
TypeScript full stack
Type safety, refactoring confidence, IDE support
Docker Compose
One-command reproducible deployment across environments
feedTrade pattern for AI bot
Avoids overwriting single-callback onTrade, gets data directly from server trade handler
Half-Kelly position sizing
Reduces variance vs full Kelly while maintaining edge
Future Enhancements
PostgreSQL and TimescaleDB for trade persistence
Redis for order book caching and WebSocket pub/sub scaling
JWT authentication with multi-user accounts
Stop-limit, IOC, and FOK order types
Backtesting framework for bot strategy evaluation
Kubernetes deployment with horizontal scaling
Prometheus and Grafana monitoring
Options pricing module (Black-Scholes)
License
MIT License. Built as a production-grade portfolio project demonstrating full-stack engineering, financial systems, real-time architecture, and algorithmic trading.