velora_core/config/engine.rs
1//! Trading engine configuration types for the Velora platform.
2//!
3//! This module contains configuration structures for different trading modes:
4//! - Backtesting (historical simulation)
5//! - Live trading (real-time execution)
6
7use serde::{Deserialize, Serialize};
8
9/// Trading engine configuration.
10#[derive(Debug, Clone, Serialize, Deserialize, Default)]
11pub struct EngineConfig {
12 /// Backtesting configuration
13 pub backtest: BacktestConfig,
14
15 /// Live trading configuration
16 pub live: LiveTradingConfig,
17}
18
19/// Backtesting engine configuration.
20///
21/// Controls simulation parameters for historical testing of trading strategies.
22#[derive(Debug, Clone, Serialize, Deserialize)]
23pub struct BacktestConfig {
24 /// Initial capital for backtesting
25 /// Env: VELORA_ENGINE_BACKTEST_INITIAL_CAPITAL
26 pub initial_capital: f64,
27
28 /// Commission rate (e.g., 0.001 for 0.1%)
29 /// Env: VELORA_ENGINE_BACKTEST_COMMISSION_RATE
30 pub commission_rate: f64,
31
32 /// Slippage rate (e.g., 0.0001 for 0.01%)
33 /// Env: VELORA_ENGINE_BACKTEST_SLIPPAGE_RATE
34 pub slippage_rate: f64,
35}
36
37impl Default for BacktestConfig {
38 fn default() -> Self {
39 BacktestConfig {
40 initial_capital: 10000.0,
41 commission_rate: 0.001,
42 slippage_rate: 0.0001,
43 }
44 }
45}
46
47/// Live trading engine configuration.
48///
49/// Controls real-time trading behavior and safety parameters.
50#[derive(Debug, Clone, Serialize, Deserialize)]
51pub struct LiveTradingConfig {
52 /// Enable dry-run mode (no real orders)
53 /// Env: VELORA_ENGINE_LIVE_DRY_RUN
54 ///
55 /// **CRITICAL**: Set to `false` only for real money trading.
56 /// Default is `true` for safety.
57 #[serde(default = "default_true")]
58 pub dry_run: bool,
59
60 /// Order timeout in seconds
61 /// Env: VELORA_ENGINE_LIVE_ORDER_TIMEOUT_SECONDS
62 pub order_timeout_seconds: u64,
63
64 /// Position check interval in milliseconds
65 /// Env: VELORA_ENGINE_LIVE_POSITION_CHECK_INTERVAL_MS
66 pub position_check_interval_ms: u64,
67}
68
69fn default_true() -> bool {
70 true
71}
72
73impl Default for LiveTradingConfig {
74 fn default() -> Self {
75 LiveTradingConfig {
76 dry_run: true,
77 order_timeout_seconds: 30,
78 position_check_interval_ms: 1000,
79 }
80 }
81}