Co-Pilot / 辅助式
更新于 24 days ago

rustrade

ZZuytan
0.0k
zuytan/rustrade
84
Agent 评分

💡 摘要

一个高性能的算法交易机器人,用于市场分析和执行,使用Rust编写。

🎯 适合人群

算法交易者金融分析师对交易系统感兴趣的开发者学习交易策略的学生业余交易者

🤖 AI 吐槽:这个机器人就像过山车——刺激,但最好在没有真钱的情况下享受。

安全分析中风险

该项目使用环境变量进行配置,如果管理不当,可能会暴露敏感的API密钥。确保.env文件不包含在版本控制中,并使用安全存储来保护秘密是至关重要的。

RustTrade Agentic Bot 🦀

CI License: MIT Rust

[!WARNING] This project is not production-ready and should not be used with real money. Using this trading bot involves significant financial risks. Use it only in simulation mode (Paper Trading) or for educational purposes.

A high-performance, multi-agent algorithmic trading system built in Rust. Capable of real-time market surveillance, trend analysis, and autonomous execution. Now featuring a full Native Desktop Interface.

📸 Screenshots

🚀 Key Features

🧠 Intelligent Agents

  • Multi-Agent Architecture: 6 specialized agents (Sentinel, Scanner, Analyst, Risk Manager, Order Throttler, Executor).
  • Regime Detection: Automatically detects Bull, Bear, Sideways, and Volatile market regimes.
  • Dynamic Scanning: Real-time discovery of "Top Movers" and volatility opportunities (Stocks & Crypto).
  • System Health Monitoring: Centralized ConnectionHealthService that tracks physical connectivity and broadcasts status to all agents for safe execution.
  • Advanced Observability: Full tracing instrumentation, custom Prometheus metrics (win rate, drawdown, latency), and structured logging.

🖥️ Native User Interface (New)

  • High-Performance Dashboard: Built with egui (0.31) for zero-latency monitoring.
  • Real-Time Visuals: Live charts, interactive metric cards, and scrolling activity feed.
  • Internationalization (i18n): Fully localized in English 🇬🇧 and French 🇫🇷.
  • Manual Control: "Panic Button" and manual strategy overrides directly from the UI.

📈 Trading Strategies

  • Standard: Dual SMA Crossover (Golden/Death Cross).
  • Advanced: Triple Filter System (SMA Trend + RSI Momentum + MACD + ADX Trend Strength).
  • Dynamic: Automatically switches strategies based on Market Regime (e.g., Trend Riding vs Mean Reversion).
  • Statistical: Z-Score Mean Reversion & Statistical Momentum (Regression Slope).
  • Machine Learning: Random Forest Classifier trained on technical features (MLStrategy).
  • Trend Riding: Long-term trend following with trailing stops.
  • Mean Reversion: Contrarian strategy for overbought/oversold conditions (BB + RSI).

🛡️ Advanced Risk Management

  • Correlation Filters: Prevents exposure to highly correlated assets (Pearson matrix).
  • Sector Exposure Limits: Caps risk per industry sector.
  • Circuit Breakers: Daily Loss Limit, Max Drawdown Halt, Composite Risk Score.
  • Persistence ("No Amnesia"): Retains critical risk state (HWM, Daily Loss) across restarts.
  • Panic Mode: Blind emergency liquidation during data outages.
  • PDT Protection: Pattern Day Trader safeguards for accounts < $25k.
  • Singleton Connectivity: Unified WebSocket architecture preventing multi-connection conflicts and 406 errors.

🔬 Backtesting & Optimization

  • Historical Backtesting: Simulate strategies against past data with S&P500 benchmark comparison.
  • Parallel Execution: Ultra-fast multi-symbol batched backtesting using CPU parallelization.
  • Grid Search Optimizer: Systematically find best parameters (Sharpe, Sortino, Calmar optimization).
  • Performance Metrics: Calculates Alpha, Beta, Win Rate, and Risk-Adjusted Returns.

🛠️ Technical Stack

Core

  • Language: Rust 2024 Edition 🦀
  • Runtime: tokio (Asynchronous I/O, Channels, Actors)
  • Database: sqlx (SQLite 0.8) for local persistence of trades and candles
  • GUI: egui 0.31 + eframe (Immediate Mode GUI)

Data & Networking

  • Market Data: Alpaca API v2 (WebSocket & REST), OANDA (Forex), Polygon
  • WebSockets: tokio-tungstenite
  • Serialization: serde, serde_json

Intelligence & Math

  • Technical Indicators: ta crate + Custom Implementations (ADX, Pivots)
  • Financial Math: rust_decimal (Fixed-point arithmetic for zero precision loss)

⚙️ Configuration

The application is configured primarily via environment variables. You can set these in your shell or use a .env file in the project root.

Core & Connectivity

| Variable | Default | Description | |----------|---------|-------------| | MODE | mock | Trading mode: mock, alpaca, oanda. | | ASSET_CLASS | stock | Asset class: stock or crypto. | | ALPACA_API_KEY | - | Your Alpaca API Key. | | ALPACA_SECRET_KEY | - | Your Alpaca Secret Key. |

Risk Management

| Variable | Default | Description | |----------|---------|-------------| | RISK_APPETITE_SCORE | - | Master Override (1-9). Sets risk profile automatically. | | MAX_DAILY_LOSS_PCT | 0.02 | Max daily loss before "Kill Switch" (2%). | | MAX_DRAWDOWN_PCT | 0.1 | Max total drawdown allowed (10%). | | MAX_SECTOR_EXPOSURE_PCT | 0.30 | Max exposure to a single sector. |

Strategy Parameters

| Variable | Default | Description | |----------|---------|-------------| | STRATEGY_MODE | standard | standard, advanced, dynamic, trendriding, meanreversion. | | ADX_PERIOD | 14 | ADX smoothing period. | | ADX_THRESHOLD | 25.0 | Minimum trend strength for entry. | | RSI_THRESHOLD | 75.0 | RSI Overbought threshold. | | OBSERVABILITY_ENABLED | false | Enable Prometheus metrics server. | | OBSERVABILITY_PORT | 9090 | Port for Prometheus metrics. |

📚 Documentation

⚡ Quick Start

Prerequisites

  • Rust (Cargo)
  • Alpaca API Keys (Paper Trading)

Running the Desktop App

# 1. Configure Credentials cp .env.example .env # Edit .env with your Alpaca API keys # 2. Launch the UI cargo run --bin rustrade

Backtesting CLI

# Backtest a strategy cargo run --bin benchmark -- --symbol NVDA --start 2023-01-01 --end 2023-12-31 --strategy advanced # Parallel Mass Backtest cargo run --bin benchmark -- --symbol AAPL,TSLA,NVDA,MSFT --start 2024-01-01 --end 2024-03-31 --parallel # Optimize parameters cargo run --bin optimize -- --symbol TSLA --grid-config grid.toml # Train ML Model cargo run --bin train_ml

🏗️ Architecture

flowchart TB subgraph Agents S[Sentinel] --> A[Analyst] A --> R[Risk Manager] R --> E[Executor] L[Listener] --> A U[User Agent] --> A end subgraph External WS[WebSocket] --> S REST[REST API] --> S NEWS[News RSS] --> L end subgraph Core A --> STR[Strategy Engine] STR --> SIG[Signal Generator] R --> VAL[Validation Pipeline] S -.-> CH[Connection Health] E -.-> CH CH -.-> R end E --> BROKER[Broker API]

🤝 Contributing

Contributions are welcome! Please see our Contributing Guide for details on:

  • Development setup
  • Code style guidelines (cargo fmt, cargo clippy)
  • Testing requirements
  • Pull request process

📄 License

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

五维分析
清晰度8/10
创新性8/10
实用性9/10
完整性9/10
可维护性8/10
优缺点分析

优点

  • 高性能的多代理架构
  • 实时市场分析和执行
  • 全面的风险管理功能
  • 支持回测和优化

缺点

  • 尚未准备好用于真实货币交易
  • 需要技术知识进行配置
  • 高级功能的文档有限
  • 潜在的高财务风险

相关技能

web3-ethereum-defi

A
toolCo-Pilot / 辅助式
80/ 100

“README没有提到任何具体的安全措施,这引发了对依赖漏洞和潜在网络访问风险的担忧。实施依赖扫描和安全编码实践至关重要。”

pytorch

S
toolCode Lib / 代码库
92/ 100

“它是深度学习的瑞士军刀,但祝你好运能从47种安装方法里找到那个不会搞崩你系统的那一个。”

agno

S
toolCode Lib / 代码库
90/ 100

“它承诺成为智能体领域的Kubernetes,但得看开发者有没有耐心学习又一个编排层。”

免责声明:本内容来源于 GitHub 开源项目,仅供展示和评分分析使用。

版权归原作者所有 Zuytan.