Institutional-grade high-frequency trading system built with Rust
Built with Rust 2024 Edition and latest stable dependencies (Sep 2025)
- Low-latency execution: Sub-millisecond order routing with P99 tracking
- Multi-venue support: Hyperliquid, Binance Futures, Interactive Brokers
- ML-powered signals: ONNX Runtime integration with ensemble models
- Real-time risk management: Kill switches, position limits, PnL tracking
- Universe rotation: Automated asset selection with multi-source scoring
- Professional UI: 60fps egui-based terminal with Bloomberg-style density
- Secure credential storage: OS keychain integration with AES-256 encryption
Rust Installation (requires Rust 1.82+ for edition 2024):
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
rustup default stableSystem Dependencies:
macOS:
brew install pkg-config openssl dbusUbuntu/Debian:
sudo apt-get install -y pkg-config libssl-dev libdbus-1-devWindows:
- Install Visual Studio Build Tools 2022
- Enable "Desktop development with C++"
# Clone repository
git clone https://github.com/vroha/toomo.git
cd toomo
# Configure environment
cp .env.example .env
# Edit .env with your API keys:
# HYPERLIQUID_API_KEY=your_key
# HYPERLIQUID_SECRET=your_secret
# ENABLE_UNIVERSE=false
# Build release binaries
cargo build --release
# Run tests
cargo test --all
# Start trading engine (paper trading mode)
cargo run --release -p engine
# In another terminal, launch desktop UI
cargo run --release -p terminal- Runtime: Tokio 1.47 async runtime
- Web: Axum 0.8, Hyper 1.7, Tower 0.5
- Data: Arrow/Parquet 56.2, AWS SDK 1.106
- ML: ONNX Runtime 2.0-rc.10 with ndarray
- UI: egui 0.32.3 with 60fps rendering
- Messaging: async-nats 0.42 (optional)
โโโโโโโโโโโโโโโโโโโ WebSocket โโโโโโโโโโโโโโโโโโโโ
โ Terminal UI โ โโโโโโโโโโโโโโโโโโบ โ Trading Engine โ
โ (egui 0.32) โ Metrics/Risk โ (Tokio 1.47) โ
โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโ
โ
โโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโ
โ โ โ
โโโโโโผโโโโโ โโโโโโผโโโโโ โโโโโโผโโโโโ
โ Adaptersโ โ Featuresโ โ ML Pool โ
โ Layer โ โ Builder โ โ (ONNX) โ
โโโโโโฌโโโโโ โโโโโโโโโโโ โโโโโโโโโโโ
โ
โโโโโโโโโโโโโโผโโโโโโโโโโโโโ
โ โ โ
โโโโโโผโโโโโ โโโโโผโโโโโ โโโโโผโโโโโ
โHyperlqd โ โBinance โ โ IBKR โ
โโโโโโโโโโโ โโโโโโโโโโ โโโโโโโโโโ
Edit config/engine.toml:
[engine]
mode = "paper" # "paper" | "live" | "backtest"
feature_window_size = 1000
inference_timeout_ms = 3
[gate]
min_edge_bps = 5.0
min_confidence = 0.5
max_spread_bps = 10.0
[risk]
max_notional_per_symbol = 100000.0
max_total_notional = 500000.0
max_loss_per_day = 10000.0Credentials are stored in OS keychain (macOS Keychain, Windows Credential Manager, Linux Secret Service):
use common::security::{CredentialStore, ApiCredentials};
let store = CredentialStore::new()?;
let creds = ApiCredentials::new(api_key, api_secret, is_paper);
store.save(Venue::Hyperliquid, "main", &creds)?;- Latency: P99 < 1ms for feature computation
- Throughput: 1000+ snapshots/sec per symbol
- ML Inference: < 3ms timeout with fallback
- UI: Stable 60fps rendering
# Unit tests
cargo test
# Integration tests
cargo test --test integration
# Benchmarks
cargo bench
# Load testing (requires live connection)
cargo test --release --test load -- --ignored# Build engine image
docker build -t hft-engine -f Dockerfile.engine .
# Run with docker-compose
docker-compose up -d
# View logs
docker-compose logs -f engine# Build for Linux (if on macOS)
cargo build --release --target x86_64-unknown-linux-gnu
# Deploy to EC2 with systemd
scp target/release/engine user@ec2:~/
scp hft-engine.service user@ec2:/etc/systemd/system/
ssh user@ec2 'sudo systemctl enable --now hft-engine'# Watch mode with auto-rebuild
cargo watch -x 'check --all' -x 'test --all'
# Format code
cargo fmt --all
# Lint with Clippy
cargo clippy --all-targets --all-features -- -D warnings
# Generate documentation
cargo doc --no-deps --open
# Profile with flamegraph (requires cargo-flamegraph)
cargo flamegraph --bin engine| Key | Action |
|---|---|
Ctrl+P |
Toggle Paper/Live mode |
Ctrl+K |
Activate kill switch |
Ctrl+R |
Refresh universe |
Ctrl+L |
Clear logs |
Ctrl+Q |
Quit |
Space |
Pause/Resume trading |
Engine exposes metrics on http://localhost:9090/metrics:
# Latency metrics
hft_ingest_duration_us
hft_feature_duration_us
hft_model_duration_us
hft_route_duration_us
# Throughput
hft_snapshots_per_sec
hft_orders_per_sec
# Errors
hft_dropped_frames_total
hft_model_timeouts_total
hft_order_rejects_total
Import the dashboard from config/grafana/hft-dashboard.json
Connect to real-time metrics:
// Performance metrics
ws://localhost:8081/metrics
// Risk snapshot
ws://localhost:8081/risk
// Critical alerts
ws://localhost:8081/alertsPlace ONNX models in models/ directory:
models/
โโโ crypto/
โ โโโ idec.onnx # Deep classifier
โ โโโ transformer.onnx # Attention model
โ โโโ gbdt.onnx # Gradient boosting
โ โโโ edge.onnx # Fast edge model (< 1ms)
โโโ equity/
โโโ idec.onnx
โโโ transformer.onnx
โโโ gbdt.onnx
โโโ edge.onnx
Models automatically loaded on startup. Falls back to rule-based if unavailable.
- Perpetual futures
- WebSocket L2 book updates
- Sub-millisecond order placement
- Native USDC settlement
- USDT and COIN-M futures
- REST + WebSocket APIs
- Position mode: One-way or Hedge
- Auto-deleverage protection
- US equities
- TWS Gateway integration
- Real-time market data (Level 1/2)
- Pre/post market trading
The system computes 13 core features per symbol:
- Order Flow Imbalance (OFI): Bid/ask flow delta
- Order Book Imbalance (OBI): Size imbalance at BBO
- Microprice: Volume-weighted mid
- Spread (bps): Relative bid-ask spread
- Depth Imbalance: Total bid/ask size ratio
- Realized Volatility: Returns variance
- ATR: Average true range
- Funding Rate: 8h funding (futures)
- Impact Curve: A * notional^ฮฒ
- VWAP Ratio: Current mid / recent VWAP
- Depth Alpha/Beta: Power law parameters
- Trade Intensity: Recent print frequency
- Time Features: Time-of-day, day-of-week
Features normalized and fed to ONNX models at ~1ms latency.
// Routing decision tree
if urgency > 0.8 && edge > 10bps {
OrderStyle::TakerNow // Market order
} else if urgency > 0.5 && spread < 3bps {
OrderStyle::Sniper // Join BBO
} else {
OrderStyle::MakerPassive // Post-only limit
}Size calculation uses Kelly criterion with conservative scaling:
size = base_size * confidenceยฒ * (1 + urgency * 0.5)- Daily loss exceeds configured limit
- Position concentration > 25% of portfolio
- Unrealized loss > 2x average daily range
- Manual activation via UI or API
- Per-symbol notional cap
- Total portfolio notional cap
- Max leverage multiplier
- Max holding time per position
- Wide spread detection (> 10bps)
- Low liquidity warning (< $500k)
- Extreme volatility pause (> 3 ATR move)
Full Rebuild (every 120 min):
- Fetch data from 10+ sources (Hyperliquid, DexScreener, GeckoTerminal, Birdeye, The Graph, CryptoPanic, etc.)
- Compute composite scores per asset
- Filter by volume, liquidity, availability
- Select top 30 crypto + 20 equity
- Store snapshot to database
Quick Refresh (every 15 min):
- Re-score current 50-asset universe
- Refresh real-time metrics only
- Select top 7 crypto + 3 equity for active trading
- Apply anti-whiplash rules (10% score delta minimum)
Structured JSON logs with tracing:
# View real-time logs
RUST_LOG=debug cargo run -p engine 2>&1 | jq
# Filter by component
RUST_LOG=engine::router=trace cargo run -p engine
# Production logging
RUST_LOG=info,engine::router=debug cargo run --release -p engine# Check system load
top -o cpu
# Verify P99 latency
curl http://localhost:9090/metrics | grep p99
# Reduce feature window
# Edit config/engine.toml: feature_window_size = 500# Check ONNX Runtime logs
RUST_LOG=ort=debug cargo run -p engine
# Increase timeout (default 3ms)
# Edit config/engine.toml: inference_timeout_ms = 5
# Disable slow models
# Remove transformer.onnx and gbdt.onnx, keep edge.onnx only# Check connection status
curl http://localhost:8081/health
# Review WS logs
RUST_LOG=engine::ws_server=trace cargo run -p engine
# Increase buffer size in crates/adapters/src/hyperliquid.rs- Fork the repository
- Create feature branch:
git checkout -b feature/amazing-feature - Commit changes:
git commit -m 'Add amazing feature' - Push to branch:
git push origin feature/amazing-feature - Open Pull Request
- Follow Rust API Guidelines
- Maintain test coverage > 80%
- Document all public APIs
- Run
cargo fmtandcargo clippybefore committing
MIT License - See LICENSE file for details
This software is for educational and research purposes only.
- Trading cryptocurrencies and equities involves substantial risk of loss
- Past performance does not guarantee future results
- The authors are not responsible for any financial losses
- Always test thoroughly in paper trading mode first
- Consult a qualified financial advisor before live trading
- This is NOT investment advice
- Rust Community for exceptional tooling
- ONNX Runtime team for high-performance inference
- egui for immediate-mode GUI framework
- Tokio for async runtime excellence
- HFT Research Community for pioneering techniques
- ๐ง Email: [email protected]
- ๐ฌ Discord: Join Server
- ๐ Issues: GitHub Issues
- ๐ Wiki: Project Wiki
- Multi-threading for order book processing
- Parquet export for ML training pipeline
- Advanced universe filters (sentiment, on-chain)
- Mobile monitoring app (React Native)
- Options market making strategies
- Cross-venue arbitrage detection
- Reinforcement learning agent integration
- Multi-account portfolio optimization
- FIX protocol support
- Market replay for backtesting
- GPU-accelerated feature computation
- Real-time strategy parameter tuning
Built with โค๏ธ by the Toomo Team
Last Updated: October 2025 โข Rust Edition 2024