Skip to content

Erio-Harrison/rust-trade

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

87 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Rust Trade

A comprehensive cryptocurrency trading system with real-time data collection, advanced backtesting capabilities, and a professional desktop interface.

Rust License Platform

๐ŸŽฏ Overview

Rust Trade combines high-performance market data processing with sophisticated backtesting tools, delivering a complete solution for cryptocurrency quantitative trading. The system features real-time data collection from exchanges, a powerful backtesting engine with multiple strategies, and an intuitive desktop interface.

๐Ÿ—๏ธ Architecture

Live Data Collection Mode

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚   Exchange      โ”‚โ”€โ”€โ”€โ–ถโ”‚    Service      โ”‚โ”€โ”€โ”€โ–ถโ”‚   Repository    โ”‚
โ”‚   (WebSocket)   โ”‚    โ”‚  (Processing)   โ”‚    โ”‚   (Storage)     โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
         โ”‚                       โ”‚                       โ”‚
         โ”‚                       โ–ผ                       โ–ผ
    Binance API           โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”         โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
    - Real-time data      โ”‚ Multi-Level โ”‚         โ”‚ PostgreSQL  โ”‚
    - Paper trading       โ”‚    Cache    โ”‚         โ”‚ Database    โ”‚
                          โ”‚ (L1 + L2)   โ”‚         โ”‚             โ”‚
                          โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜         โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                                    โ”‚
                                    โ–ผ
                          โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                          โ”‚ Paper Trading   โ”‚
                          โ”‚    Engine       โ”‚
                          โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Desktop Application Mode

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚   Next.js       โ”‚โ”€โ”€โ”€โ–ถโ”‚  Tauri Commands โ”‚โ”€โ”€โ”€โ–ถโ”‚ Trading Common  โ”‚
โ”‚   Frontend      โ”‚    โ”‚   (src-tauri)   โ”‚    โ”‚    (Library)    โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                                                       โ”‚
                               โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                               โ–ผ                                               โ–ผ
                       โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”                             โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                       โ”‚ Backtest Engine โ”‚                             โ”‚   Repository    โ”‚
                       โ”‚  + Strategies   โ”‚                             โ”‚   + Database    โ”‚
                       โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜                             โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

๐Ÿ“ Project Structure

rust-trade/
โ”œโ”€โ”€ assets/                # Project assets and screenshots
โ”œโ”€โ”€ config/                # Global configuration files
โ”‚   โ”œโ”€โ”€ development.toml   # Development environment config
โ”‚   โ”œโ”€โ”€ production.toml    # Production environment config
โ”‚   โ”œโ”€โ”€ schema.sql         # PostgreSQL table definitions
โ”‚   โ””โ”€โ”€ test.toml          # Test environment config
โ”œโ”€โ”€ frontend/              # Next.js frontend application
โ”‚   โ”œโ”€โ”€ src/               # Frontend source code
โ”‚   โ”‚   โ”œโ”€โ”€ app/           # App router pages
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ page.tsx   # Dashboard homepage
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ backtest/  # Backtesting interface
โ”‚   โ”‚   โ”œโ”€โ”€ components/    # Reusable UI components
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ layout/    # Layout components
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ ui/        # shadcn/ui components
โ”‚   โ”‚   โ””โ”€โ”€ types/         # TypeScript type definitions
โ”‚   โ”œโ”€โ”€ tailwind.config.js # Tailwind CSS configuration
โ”‚   โ””โ”€โ”€ package.json       # Frontend dependencies
โ”œโ”€โ”€ src-tauri/             # Desktop application backend
โ”‚   โ”œโ”€โ”€ src/               # Tauri command handlers and state management
โ”‚   โ”‚   โ”œโ”€โ”€ commands.rs    # Tauri command implementations
โ”‚   โ”‚   โ”œโ”€โ”€ main.rs        # Application entry point
โ”‚   โ”‚   โ”œโ”€โ”€ state.rs       # Application state management
โ”‚   โ”‚   โ””โ”€โ”€ types.rs       # Frontend interface types
โ”‚   โ”œโ”€โ”€ Cargo.toml         # Tauri dependencies (uses trading-common)
โ”‚   โ””โ”€โ”€ tauri.conf.json    # Tauri configuration
โ”œโ”€โ”€ trading-common/        # Shared library for all crates
โ”‚   โ”œโ”€โ”€ src/
โ”‚   โ”‚   โ”œโ”€โ”€ backtest/      # Backtesting engine and strategies
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ engine.rs  # Core backtesting logic
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ metrics.rs # Performance calculations
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ portfolio.rs # Portfolio management
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ strategy/  # Trading strategies (RSI, SMA)
โ”‚   โ”‚   โ”œโ”€โ”€ data/          # Data layer
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ cache.rs   # Multi-level caching system
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ repository.rs # Database operations
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ types.rs   # Core data structures
โ”‚   โ”‚   โ””โ”€โ”€ lib.rs         # Library entry point
โ”‚   โ””โ”€โ”€ Cargo.toml         # Common dependencies
โ”œโ”€โ”€ trading-core/          # CLI trading system
โ”‚   โ”œโ”€โ”€ src/
โ”‚   โ”‚   โ”œโ”€โ”€ exchange/      # Exchange integrations
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ binance.rs # Binance WebSocket client
โ”‚   โ”‚   โ”œโ”€โ”€ live_trading/  # Paper trading system
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ paper_trading.rs # Real-time strategy execution
โ”‚   โ”‚   โ”œโ”€โ”€ service/       # Business logic layer
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ market_data.rs # Data processing service
โ”‚   โ”‚   โ”œโ”€โ”€ config.rs      # Configuration management
โ”‚   โ”‚   โ”œโ”€โ”€ lib.rs         # Library entry point (re-exports trading-common)
โ”‚   โ”‚   โ””โ”€โ”€ main.rs        # CLI application entry point
โ”‚   โ”œโ”€โ”€ benches/           # Performance benchmarks
โ”‚   โ”œโ”€โ”€ Cargo.toml         # Core dependencies
โ”‚   โ””โ”€โ”€ README.md          # Core system documentation
โ””โ”€โ”€ README.md              # This file

๐Ÿš€ Quick Start

Prerequisites

1. Clone the Repository

git clone https://github.com/Erio-Harrison/rust-trade.git
cd rust-trade

2. Database Setup

# Create database
createdb trading_core

# Set up schema
Run the SQL commands found in the config folder to create the database tables.

3. Environment Configuration

Create .env files in both root directory and trading-core/:

# .env
DATABASE_URL=postgresql://username:password@localhost/trading_core
REDIS_URL=redis://127.0.0.1:6379
RUN_MODE=development

4. Install Dependencies

# Install Rust dependencies
cd trading-core
cargo build
cd ..

# Install frontend dependencies
cd frontend
npm install
cd ..

# Install Tauri dependencies
cd src-tauri
cargo build
cd ..

PS:

๐ŸŽฎ Running the Application

Option 1: Desktop Application (Recommended)

# Development mode with hot reload
cd frontend && npm run tauri dev
# or alternatively
cd frontend && cargo tauri dev

# Production build
cd frontend && npm run tauri build
# or alternatively
cd frontend && cargo tauri build

Option 2: Core Trading System (CLI)

cd trading-core

# Start live data collection
cargo run live

# Start live data collection with paper trading
cargo run live --paper-trading

# Run backtesting interface
cargo run backtest

# Show help
cargo run -- --help

Option 3: Web Interface Only

cd frontend

# Development server
npm run dev

# Production build
npm run build
npm start

๐Ÿ“Š Features

Live Data Collection

  • Real-time WebSocket connections to cryptocurrency exchanges
  • High-performance data processing (~390ยตs single insert, ~13ms batch)
  • Multi-level caching with Redis and in-memory storage
  • Automatic retry mechanisms and error handling

Advanced Backtesting

  • Multiple trading strategies (SMA, RSI)
  • Professional performance metrics (Sharpe ratio, drawdown, win rate)
  • Portfolio management with P&L tracking
  • Interactive parameter configuration

Desktop Interface

  • Real-time data visualization
  • Intuitive strategy configuration
  • Comprehensive result analysis
  • Cross-platform support (Windows, macOS, Linux)

๐Ÿ–ผ๏ธ Screenshots

Backtest Configuration

Backtest Configuration

Results Dashboard

Results Dashboard

Trade Analysis

Trade Analysis

โš™๏ธ Configuration

Trading Symbols

Edit config/development.toml:

# Trading pairs to monitor
symbols = ["BTCUSDT", "ETHUSDT", "ADAUSDT"]

[server]
host = "0.0.0.0"
port = 8080

[database]
max_connections = 5
min_connections = 1
max_lifetime = 1800

[cache]
[cache.memory]
max_ticks_per_symbol = 1000
ttl_seconds = 300

[cache.redis]
pool_size = 10
ttl_seconds = 3600
max_ticks_per_symbol = 10000

Logging

Set log levels via environment variables:

# Application logs
RUST_LOG=trading_core=info

# Debug mode
RUST_LOG=trading_core=debug,sqlx=info

๐Ÿ“ˆ Performance

Based on comprehensive benchmarks:

Operation Performance Use Case
Single tick insert ~390ยตs Real-time data
Batch insert (100) ~13ms Bulk processing
Cache hit ~10ยตs Data retrieval
Historical query ~450ยตs Backtesting

๐Ÿ”ง Development

Running Tests

# Core system tests
cd trading-core
cargo test

# Benchmarks
cargo bench

# Frontend tests
cd frontend
npm test

Building for Production

# Build trading core
cd trading-core
cargo build --release

# Build desktop app
cd ../frontend
npm run tauri build

# Build web interface
npm run build

๐Ÿ“š Documentation

  • Trading Core: See trading-core/README.md for detailed backend documentation
  • Desktop App: See src-tauri/README.md for Tauri application details

๐Ÿค Contributing

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

๐Ÿ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

๐Ÿ‘จโ€๐Ÿ’ป Author

Erio Harrison - GitHub


Built with โค๏ธ using Rust, Tauri, and Next.js

About

A quantitative trading system built with Rust.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages