High-frequency trading engine powered by Rust + Python AI
LocoHFT is a hybrid high-frequency trading system combining Rust's blazing-fast execution speed with Python's AI/ML capabilities. Features an interactive terminal UI, risk management, and both practice and live trading modes.
| Feature | Description |
|---|---|
| โก Ultra-Low Latency | Sub-microsecond order execution via Rust engine |
| ๐ค AI Trading Strategies | Python-embedded ML algorithms via PyO3 |
| ๐ Smart Analysis | Bollinger Bands mean reversion, momentum detection |
| ๐ก๏ธ Risk Management | Position limits, VaR calculations, automatic stop-loss |
| ๐ฎ Practice Mode | Paper trading with $100K virtual balance |
| ๐ก AI Recommendations | Personalized portfolio allocation based on goals |
| ๐ Learning Center | Built-in educational content for beginners |
| ๐พ SQLite Persistence | Portfolio and trade history storage |
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Terminal UI โ
โ (dialoguer + indicatif) โ
โโโโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โโโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Rust Core โ
โ โโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโ โ
โ โ Engine โ โ Risk Mgmt โ โ Portfolio โ โ
โ โ Execution โ โ VaR โ โ Manager โ โ
โ โโโโโโโโฌโโโโโโโโ โโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโ โ
โโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ PyO3 Bridge
โโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Python AI Layer โ
โ โโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ LocoHFTStrategy โ โ Recommendation Engine โ โ
โ โ (Bollinger Bands)โ โ (Portfolio Optimizer) โ โ
โ โโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
# Clone the repository
git clone https://github.com/yourusername/LocoHFT.git
cd LocoHFT
# Build release binary
cargo build --release
# Run the application
./target/release/LocoHFT.exe# Run the standalone build script (downloads required tools automatically)
build-standalone.bat
# Output will be in dist/LocoHFT.exe| Option | Description |
|---|---|
| ๐ Stock Analysis | Analyze individual stocks, view market overview |
| ๐ฐ My Portfolio | View holdings, trade history, buy/sell stocks |
| ๐ค AI Trading | Enable automated AI trading with risk controls |
| ๐ Learning Center | Educational content for beginners |
| โ๏ธ Settings | Toggle practice/live mode, configure API keys |
The built-in LocoHFTStrategy uses Bollinger Bands Mean Reversion:
# Buys when price < lower band (oversold)
# Sells when price > upper band (overbought)
upper = SMA + 2ฯ
lower = SMA - 2ฯ| Mode | Risk | Balance | Purpose |
|---|---|---|---|
| ๐ฎ Practice | None | $100,000 virtual | Learn & test strategies |
| ๐ด Live | Real | Your actual funds | Real trading |
For real market data, get a free API key from Alpha Vantage:
Settings โ API Keys โ Enter your key
Without API keys, the app uses demo data for learning.
Edit python/strategy.py to customize:
self.lookback = 20 # Bollinger Bands period
self.position_limit = 1000 # Max shares per symbol
self.var_limit = 0.02 # 2% Value-at-Risk limitLocoHFT/
โโโ src/
โ โโโ main.rs # TUI application entry
โ โโโ engine.rs # Execution & risk engine
โ โโโ python_bridge.rs # PyO3 Python interop
โโโ python/
โ โโโ strategy.py # AI trading strategies
โ โโโ recommendations.py # Portfolio optimizer
โ โโโ analytics.py # Data analysis tools
โโโ Cargo.toml
โโโ README.md
- Edit
python/strategy.py - Implement your logic in
on_market_data() - Return a
Signaldict with action, size, price, confidence
def on_market_data(self, symbol, price, volume, timestamp):
# Your custom logic here
if should_buy:
return Signal("BUY", 100, price, 0.85, {}).dict()
return None# Run unit tests
cargo test
# Run with logging
RUST_LOG=debug cargo runtokio- Async runtimepyo3- Python interoperabilitydialoguer/indicatif- Terminal UIrusqlite- Embedded databasecrossbeam- High-performance channelsreqwest- HTTP client for APIs
- Standard library only (embedded)
Trading involves significant risk of loss.
- This software is for educational purposes
- Past performance does not guarantee future results
- Only trade with money you can afford to lose
- The AI is a tool, not financial advice
- Always do your own research
MIT License - See LICENSE for details.
- Built with โค๏ธ in Rust
- Python AI integration via PyO3
- Terminal UI powered by console-rs
Made for traders who love speed and intelligence
๐ฆ โก ๐