Skip to content

Latest commit

ย 

History

3 Commits

Folders and files

NameName
Last commit message
Last commit date
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿš€ LocoHFT

High-frequency trading engine powered by Rust + Python AI

Rust Python License

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.

Terminal UI Demo


โœจ Features

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

๐Ÿ—๏ธ Architecture

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                        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)    โ”‚     โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜      โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜     โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

๐Ÿš€ Quick Start

Prerequisites

Build & Run

# 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

Windows Standalone Build

# Run the standalone build script (downloads required tools automatically)
build-standalone.bat

# Output will be in dist/LocoHFT.exe

๐Ÿ“– Usage Guide

Main Menu

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

AI Trading Strategy

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ฯƒ

Practice Mode vs Live Trading

Mode Risk Balance Purpose
๐ŸŽฎ Practice None $100,000 virtual Learn & test strategies
๐Ÿ”ด Live Real Your actual funds Real trading

โš™๏ธ Configuration

API Keys (Optional)

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.

Risk Settings

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 limit

๐Ÿ› ๏ธ Development

Project Structure

LocoHFT/
โ”œโ”€โ”€ 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

Adding Custom Strategies

  1. Edit python/strategy.py
  2. Implement your logic in on_market_data()
  3. Return a Signal dict 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

๐Ÿงช Testing

# Run unit tests
cargo test

# Run with logging
RUST_LOG=debug cargo run

๐Ÿ“ฆ Dependencies

Rust Crates

  • tokio - Async runtime
  • pyo3 - Python interoperability
  • dialoguer / indicatif - Terminal UI
  • rusqlite - Embedded database
  • crossbeam - High-performance channels
  • reqwest - HTTP client for APIs

Python Libraries

  • Standard library only (embedded)

โš ๏ธ Risk Disclaimer

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

๐Ÿ“„ License

MIT License - See LICENSE for details.


๐Ÿ™ Acknowledgments

  • Built with โค๏ธ in Rust
  • Python AI integration via PyO3
  • Terminal UI powered by console-rs

Made for traders who love speed and intelligence
๐Ÿฆ€ โšก ๐Ÿ

About

Rust + Python AI trading engine with sub-microsecond execution

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages