Skip to main content

velora_core/config/
exchange.rs

1//! Exchange connection configuration for the Velora platform.
2//!
3//! This module contains configuration for connecting to cryptocurrency
4//! exchanges and managing API rate limits.
5
6use serde::{Deserialize, Serialize};
7
8/// Exchange connection configuration.
9///
10/// Configures connection parameters for a specific cryptocurrency exchange.
11///
12/// # Security Note
13///
14/// API secrets should **never** be committed to configuration files.
15/// Use environment variables instead:
16/// - `VELORA_EXCHANGES_<NAME>_API_KEY`
17/// - `VELORA_EXCHANGES_<NAME>_API_SECRET`
18///
19/// # Example
20///
21/// ```toml
22/// [exchanges.binance]
23/// name = "binance"
24/// testnet = true
25/// rate_limit.requests_per_second = 10
26/// rate_limit.orders_per_second = 5
27/// ```
28#[derive(Debug, Clone, Serialize, Deserialize)]
29pub struct ExchangeConfig {
30    /// Exchange name (e.g., "binance", "coinbase")
31    pub name: String,
32
33    /// API key (optional for public data)
34    /// Env: VELORA_EXCHANGES_<NAME>_API_KEY
35    #[serde(skip_serializing_if = "Option::is_none")]
36    pub api_key: Option<String>,
37
38    /// API secret (optional for public data)
39    /// Env: VELORA_EXCHANGES_<NAME>_API_SECRET
40    /// Note: For security, prefer env vars over config files
41    #[serde(skip_serializing_if = "Option::is_none")]
42    pub api_secret: Option<String>,
43
44    /// Use testnet/sandbox environment
45    /// Env: VELORA_EXCHANGES_<NAME>_TESTNET
46    #[serde(default)]
47    pub testnet: bool,
48
49    /// Custom REST API URL (overrides default)
50    #[serde(skip_serializing_if = "Option::is_none")]
51    pub rest_url: Option<String>,
52
53    /// Custom WebSocket URL (overrides default)
54    #[serde(skip_serializing_if = "Option::is_none")]
55    pub ws_url: Option<String>,
56
57    /// Rate limiting configuration
58    #[serde(default)]
59    pub rate_limit: RateLimitConfig,
60}
61
62/// Rate limiting configuration for exchange API calls.
63///
64/// Prevents exceeding exchange API rate limits and potential bans.
65#[derive(Debug, Clone, Serialize, Deserialize)]
66pub struct RateLimitConfig {
67    /// Maximum requests per second
68    /// Env: VELORA_RATE_LIMIT_REQUESTS_PER_SECOND
69    pub requests_per_second: u32,
70
71    /// Maximum orders per second
72    /// Env: VELORA_RATE_LIMIT_ORDERS_PER_SECOND
73    pub orders_per_second: u32,
74}
75
76impl Default for RateLimitConfig {
77    fn default() -> Self {
78        RateLimitConfig {
79            requests_per_second: 10,
80            orders_per_second: 5,
81        }
82    }
83}