Skip to main content

velora_core/config/
risk.rs

1//! Risk management configuration for the Velora platform.
2//!
3//! This module defines risk limits and position constraints to protect
4//! trading capital and prevent catastrophic losses.
5
6use serde::{Deserialize, Serialize};
7use std::collections::HashMap;
8
9/// Risk management configuration.
10///
11/// Defines limits and constraints to protect trading capital.
12#[derive(Debug, Clone, Serialize, Deserialize)]
13pub struct RiskConfig {
14    /// Maximum position size per trade
15    /// Env: VELORA_RISK_MAX_POSITION_SIZE
16    pub max_position_size: f64,
17
18    /// Maximum total exposure across all positions
19    /// Env: VELORA_RISK_MAX_TOTAL_EXPOSURE
20    pub max_total_exposure: f64,
21
22    /// Maximum drawdown percentage before stopping
23    /// Env: VELORA_RISK_MAX_DRAWDOWN_PERCENT
24    pub max_drawdown_percent: f64,
25
26    /// Maximum daily loss before stopping
27    /// Env: VELORA_RISK_MAX_DAILY_LOSS
28    pub max_daily_loss: f64,
29
30    /// Per-symbol position limits (prefer config file)
31    ///
32    /// Example:
33    /// ```toml
34    /// [risk.position_limits]
35    /// "BTC/USDT" = 5000.0
36    /// "ETH/USDT" = 2000.0
37    /// ```
38    #[serde(default)]
39    pub position_limits: HashMap<String, f64>,
40}
41
42impl Default for RiskConfig {
43    fn default() -> Self {
44        RiskConfig {
45            max_position_size: 1000.0,
46            max_total_exposure: 10000.0,
47            max_drawdown_percent: 20.0,
48            max_daily_loss: 500.0,
49            position_limits: HashMap::new(),
50        }
51    }
52}