How jensnesten/rust_bt works
Main Components
• rust_core: This is the heart of the project. It implements the core trading engine including data handling, execution logic, strategies, order management, position tracking, hedging, and other essential trading functionalities. It also contains shared code that is reused by both backtesting and live trading modes.
• rust_bt: The backtesting interface. This component connects the core engine with historical market data (OHLC) to simulate trading scenarios over past data. It interacts with rust_core to run strategies for backtesting.
• rust_live: The live trading interface. It handles real-time market data streaming (currently setup for Saxo Bank’s SaxoOpenAPI) and connects live data with the core engine to execute live trading strategies.
• rust_ml: The machine learning integration module. This part loads and applies pretrained models (and scalers) for inference on both historical and live data, and includes auxiliary tools for model conversion and export.
Relationships and Interactions
• Within rust_core, show sub-components such as:
– Strategies (implemented in rust_core/src/strategies)
– Data Handling (rust_core/src/data_handler)
– Position & Trade Management (position and engine modules)
– Hedging and other utilities.
• The rust_ml module should be connected to rust_core to show how its inference outputs could modify or signal trading decisions (e.g., enhancing strategies within rust_core).
Architectural Patterns and Design Principles
• Modular Separation: Emphasize that while the core trading logic is centralized in rust_core, interfaces for different operational modes (backtest, live, and ML) are clearly separated.
• Strategy Pattern: Strategies implement a common trait (either Strategy or LiveStrategy) so that the trading logic can be easily extended.
• Data Flow Pipeline: Illustrate the sequential data processing from input (historical CSV files or live API streams), through the core engine (order book management, order execution, position management), and output (trade logs, position updates, plots).
• Extensibility: Show how additional components (e.g., new asset classes, alternate data sources) could be added with minimal changes to the core.
Technologies and Frameworks
• Rust: Identify it is the primary language with Cargo as the build system (each component has its Cargo.toml).
• For plotting, note the built-in equity curve plotting within backtesting.
• Machine Learning: Indicate integration with PyTorch models and scalers, as seen in rust_ml.
• API Integration: Mention the use of SaxoOpenAPI within the live trading module.