pub struct VeloraConfig {
pub exchanges: HashMap<String, ExchangeConfig>,
pub engine: EngineConfig,
pub risk: RiskConfig,
pub logging: LoggingConfig,
pub database: DatabaseConfig,
}Expand description
Main configuration for the Velora platform.
Environment variables can override any setting using the pattern:
VELORA_<SECTION>_<KEY> (e.g., VELORA_ENGINE_LIVE_DRY_RUN=false)
§Examples
use velora_core::VeloraConfig;
// Load from all sources (files + env vars)
let config = VeloraConfig::from_gonfig().unwrap();Fields§
§exchanges: HashMap<String, ExchangeConfig>Exchange configurations Env: VELORA_EXCHANGES_* (complex, prefer config file)
engine: EngineConfigEngine configuration Env: VELORA_ENGINE_*
risk: RiskConfigRisk management configuration Env: VELORA_RISK_*
logging: LoggingConfigLogging configuration Env: VELORA_LOGGING_*
database: DatabaseConfigDatabase configuration Env: VELORA_DATABASE_*
Implementations§
Source§impl VeloraConfig
impl VeloraConfig
pub fn from_gonfig() -> Result<Self>
pub fn from_gonfig_with_builder(builder: ConfigBuilder) -> Result<Self>
pub fn gonfig_builder() -> ConfigBuilder
Source§impl VeloraConfig
impl VeloraConfig
Sourcepub fn from_file<P: AsRef<Path>>(path: P) -> Result<Self>
pub fn from_file<P: AsRef<Path>>(path: P) -> Result<Self>
Load configuration from a single TOML file with environment variable overrides.
This is a convenience wrapper around gonfig’s ConfigBuilder.
§Examples
use velora_core::VeloraConfig;
let config = VeloraConfig::from_file("config.toml").unwrap();Examples found in repository?
13fn main() -> Result<(), Box<dyn std::error::Error>> {
14 println!("=== Velora Configuration Loading Examples ===\n");
15
16 // Example 1: Load from single file
17 println!("1. Loading from single file (base.toml):");
18 match VeloraConfig::from_file("config/base.toml") {
19 Ok(config) => {
20 println!(" ✓ Loaded successfully");
21 println!(" Database backend: {:?}", config.database.backend);
22 println!(" Logging level: {}", config.logging.level);
23 println!();
24 }
25 Err(e) => {
26 println!(" ✗ Failed to load: {e}");
27 println!(" (This is expected if config/base.toml doesn't exist)\n");
28 }
29 }
30
31 // Example 2: Load layered configuration (base + testing)
32 println!("2. Loading layered config (base.toml + testing.toml):");
33 match VeloraConfig::from_files(&["config/base.toml", "config/testing.toml"]) {
34 Ok(config) => {
35 println!(" ✓ Loaded successfully");
36 println!(" Database backend: {:?}", config.database.backend);
37 println!(" Logging level: {}", config.logging.level);
38 println!(" Max position size: {}", config.risk.max_position_size);
39 println!();
40 }
41 Err(e) => {
42 println!(" ✗ Failed to load: {e}");
43 println!(" (This is expected if config files don't exist)\n");
44 }
45 }
46
47 // Example 3: Load with optional local overrides
48 println!("3. Loading with optional local.toml override:");
49 match VeloraConfig::from_files_optional(&[
50 ("config/base.toml", true), // required
51 ("config/testing.toml", true), // required
52 ("config/local.toml", false), // optional (won't error if missing)
53 ]) {
54 Ok(config) => {
55 println!(" ✓ Loaded successfully");
56 println!(" Database backend: {:?}", config.database.backend);
57 println!();
58 }
59 Err(e) => {
60 println!(" ✗ Failed to load: {e}");
61 println!();
62 }
63 }
64
65 // Example 4: Environment variable overrides
66 println!("4. Environment variable override example:");
67 println!(" Set: export VELORA_LOGGING_LEVEL=trace");
68 println!(" Then the logging level will override any config file value");
69 println!();
70
71 // Example 5: Demonstrate different environments
72 println!("5. Different environment configurations:\n");
73
74 let environments = vec![
75 ("Testing", vec!["config/base.toml", "config/testing.toml"]),
76 (
77 "Paper Trading",
78 vec!["config/base.toml", "config/paper-trading.toml"],
79 ),
80 (
81 "Live Trading",
82 vec!["config/base.toml", "config/live-trading.toml"],
83 ),
84 (
85 "Backtesting",
86 vec!["config/base.toml", "config/backtesting.toml"],
87 ),
88 ];
89
90 for (name, paths) in environments {
91 print!(" {name}: ");
92 match VeloraConfig::from_files(&paths) {
93 Ok(config) => {
94 println!(
95 "DB={:?}, DryRun={}, MaxPos=${}",
96 config.database.backend,
97 config.engine.live.dry_run,
98 config.risk.max_position_size
99 );
100 }
101 Err(_) => {
102 println!("(config files not found)");
103 }
104 }
105 }
106
107 println!("\n=== Configuration Priority ===");
108 println!("Highest → Lowest:");
109 println!("1. Environment variables (VELORA_*)");
110 println!("2. Last config file in list");
111 println!("3. ...");
112 println!("4. First config file in list (usually base.toml)");
113 println!("5. Default values in code");
114
115 println!("\n=== Usage Examples ===");
116 println!("Development:");
117 println!(" cargo run -- --config config/base.toml --config config/testing.toml");
118 println!();
119 println!("Paper Trading:");
120 println!(" cargo run -- --config config/base.toml --config config/paper-trading.toml");
121 println!();
122 println!("Live Trading (⚠️ REAL MONEY):");
123 println!(" export VELORA_EXCHANGES_BINANCE_PROD_API_KEY=your_key");
124 println!(" export VELORA_EXCHANGES_BINANCE_PROD_API_SECRET=your_secret");
125 println!(" cargo run -- --config config/base.toml --config config/live-trading.toml");
126
127 Ok(())
128}Sourcepub fn from_files<P: AsRef<Path>>(paths: &[P]) -> Result<Self>
pub fn from_files<P: AsRef<Path>>(paths: &[P]) -> Result<Self>
Load configuration from multiple layered TOML files.
Files are loaded in order, with later files overriding earlier ones. Environment variables override all file-based configuration.
§Priority (highest to lowest)
- Environment variables (VELORA_*)
- Last config file in the list
- …
- First config file in the list
- Default values
§Examples
use velora_core::VeloraConfig;
// Layer environment-specific config over base config
let config = VeloraConfig::from_files(&[
"config/base.toml",
"config/paper-trading.toml",
]).unwrap();Examples found in repository?
13fn main() -> Result<(), Box<dyn std::error::Error>> {
14 println!("=== Velora Configuration Loading Examples ===\n");
15
16 // Example 1: Load from single file
17 println!("1. Loading from single file (base.toml):");
18 match VeloraConfig::from_file("config/base.toml") {
19 Ok(config) => {
20 println!(" ✓ Loaded successfully");
21 println!(" Database backend: {:?}", config.database.backend);
22 println!(" Logging level: {}", config.logging.level);
23 println!();
24 }
25 Err(e) => {
26 println!(" ✗ Failed to load: {e}");
27 println!(" (This is expected if config/base.toml doesn't exist)\n");
28 }
29 }
30
31 // Example 2: Load layered configuration (base + testing)
32 println!("2. Loading layered config (base.toml + testing.toml):");
33 match VeloraConfig::from_files(&["config/base.toml", "config/testing.toml"]) {
34 Ok(config) => {
35 println!(" ✓ Loaded successfully");
36 println!(" Database backend: {:?}", config.database.backend);
37 println!(" Logging level: {}", config.logging.level);
38 println!(" Max position size: {}", config.risk.max_position_size);
39 println!();
40 }
41 Err(e) => {
42 println!(" ✗ Failed to load: {e}");
43 println!(" (This is expected if config files don't exist)\n");
44 }
45 }
46
47 // Example 3: Load with optional local overrides
48 println!("3. Loading with optional local.toml override:");
49 match VeloraConfig::from_files_optional(&[
50 ("config/base.toml", true), // required
51 ("config/testing.toml", true), // required
52 ("config/local.toml", false), // optional (won't error if missing)
53 ]) {
54 Ok(config) => {
55 println!(" ✓ Loaded successfully");
56 println!(" Database backend: {:?}", config.database.backend);
57 println!();
58 }
59 Err(e) => {
60 println!(" ✗ Failed to load: {e}");
61 println!();
62 }
63 }
64
65 // Example 4: Environment variable overrides
66 println!("4. Environment variable override example:");
67 println!(" Set: export VELORA_LOGGING_LEVEL=trace");
68 println!(" Then the logging level will override any config file value");
69 println!();
70
71 // Example 5: Demonstrate different environments
72 println!("5. Different environment configurations:\n");
73
74 let environments = vec![
75 ("Testing", vec!["config/base.toml", "config/testing.toml"]),
76 (
77 "Paper Trading",
78 vec!["config/base.toml", "config/paper-trading.toml"],
79 ),
80 (
81 "Live Trading",
82 vec!["config/base.toml", "config/live-trading.toml"],
83 ),
84 (
85 "Backtesting",
86 vec!["config/base.toml", "config/backtesting.toml"],
87 ),
88 ];
89
90 for (name, paths) in environments {
91 print!(" {name}: ");
92 match VeloraConfig::from_files(&paths) {
93 Ok(config) => {
94 println!(
95 "DB={:?}, DryRun={}, MaxPos=${}",
96 config.database.backend,
97 config.engine.live.dry_run,
98 config.risk.max_position_size
99 );
100 }
101 Err(_) => {
102 println!("(config files not found)");
103 }
104 }
105 }
106
107 println!("\n=== Configuration Priority ===");
108 println!("Highest → Lowest:");
109 println!("1. Environment variables (VELORA_*)");
110 println!("2. Last config file in list");
111 println!("3. ...");
112 println!("4. First config file in list (usually base.toml)");
113 println!("5. Default values in code");
114
115 println!("\n=== Usage Examples ===");
116 println!("Development:");
117 println!(" cargo run -- --config config/base.toml --config config/testing.toml");
118 println!();
119 println!("Paper Trading:");
120 println!(" cargo run -- --config config/base.toml --config config/paper-trading.toml");
121 println!();
122 println!("Live Trading (⚠️ REAL MONEY):");
123 println!(" export VELORA_EXCHANGES_BINANCE_PROD_API_KEY=your_key");
124 println!(" export VELORA_EXCHANGES_BINANCE_PROD_API_SECRET=your_secret");
125 println!(" cargo run -- --config config/base.toml --config config/live-trading.toml");
126
127 Ok(())
128}Sourcepub fn from_files_optional<P: AsRef<Path>>(paths: &[(P, bool)]) -> Result<Self>
pub fn from_files_optional<P: AsRef<Path>>(paths: &[(P, bool)]) -> Result<Self>
Load configuration with optional files.
Similar to from_files, but allows some files to be optional.
Useful for optional local overrides.
§Examples
use velora_core::VeloraConfig;
// base.toml is required, local.toml is optional
let config = VeloraConfig::from_files_optional(&[
("config/base.toml", true), // required
("config/paper-trading.toml", true), // required
("config/local.toml", false), // optional override
]).unwrap();Examples found in repository?
13fn main() -> Result<(), Box<dyn std::error::Error>> {
14 println!("=== Velora Configuration Loading Examples ===\n");
15
16 // Example 1: Load from single file
17 println!("1. Loading from single file (base.toml):");
18 match VeloraConfig::from_file("config/base.toml") {
19 Ok(config) => {
20 println!(" ✓ Loaded successfully");
21 println!(" Database backend: {:?}", config.database.backend);
22 println!(" Logging level: {}", config.logging.level);
23 println!();
24 }
25 Err(e) => {
26 println!(" ✗ Failed to load: {e}");
27 println!(" (This is expected if config/base.toml doesn't exist)\n");
28 }
29 }
30
31 // Example 2: Load layered configuration (base + testing)
32 println!("2. Loading layered config (base.toml + testing.toml):");
33 match VeloraConfig::from_files(&["config/base.toml", "config/testing.toml"]) {
34 Ok(config) => {
35 println!(" ✓ Loaded successfully");
36 println!(" Database backend: {:?}", config.database.backend);
37 println!(" Logging level: {}", config.logging.level);
38 println!(" Max position size: {}", config.risk.max_position_size);
39 println!();
40 }
41 Err(e) => {
42 println!(" ✗ Failed to load: {e}");
43 println!(" (This is expected if config files don't exist)\n");
44 }
45 }
46
47 // Example 3: Load with optional local overrides
48 println!("3. Loading with optional local.toml override:");
49 match VeloraConfig::from_files_optional(&[
50 ("config/base.toml", true), // required
51 ("config/testing.toml", true), // required
52 ("config/local.toml", false), // optional (won't error if missing)
53 ]) {
54 Ok(config) => {
55 println!(" ✓ Loaded successfully");
56 println!(" Database backend: {:?}", config.database.backend);
57 println!();
58 }
59 Err(e) => {
60 println!(" ✗ Failed to load: {e}");
61 println!();
62 }
63 }
64
65 // Example 4: Environment variable overrides
66 println!("4. Environment variable override example:");
67 println!(" Set: export VELORA_LOGGING_LEVEL=trace");
68 println!(" Then the logging level will override any config file value");
69 println!();
70
71 // Example 5: Demonstrate different environments
72 println!("5. Different environment configurations:\n");
73
74 let environments = vec![
75 ("Testing", vec!["config/base.toml", "config/testing.toml"]),
76 (
77 "Paper Trading",
78 vec!["config/base.toml", "config/paper-trading.toml"],
79 ),
80 (
81 "Live Trading",
82 vec!["config/base.toml", "config/live-trading.toml"],
83 ),
84 (
85 "Backtesting",
86 vec!["config/base.toml", "config/backtesting.toml"],
87 ),
88 ];
89
90 for (name, paths) in environments {
91 print!(" {name}: ");
92 match VeloraConfig::from_files(&paths) {
93 Ok(config) => {
94 println!(
95 "DB={:?}, DryRun={}, MaxPos=${}",
96 config.database.backend,
97 config.engine.live.dry_run,
98 config.risk.max_position_size
99 );
100 }
101 Err(_) => {
102 println!("(config files not found)");
103 }
104 }
105 }
106
107 println!("\n=== Configuration Priority ===");
108 println!("Highest → Lowest:");
109 println!("1. Environment variables (VELORA_*)");
110 println!("2. Last config file in list");
111 println!("3. ...");
112 println!("4. First config file in list (usually base.toml)");
113 println!("5. Default values in code");
114
115 println!("\n=== Usage Examples ===");
116 println!("Development:");
117 println!(" cargo run -- --config config/base.toml --config config/testing.toml");
118 println!();
119 println!("Paper Trading:");
120 println!(" cargo run -- --config config/base.toml --config config/paper-trading.toml");
121 println!();
122 println!("Live Trading (⚠️ REAL MONEY):");
123 println!(" export VELORA_EXCHANGES_BINANCE_PROD_API_KEY=your_key");
124 println!(" export VELORA_EXCHANGES_BINANCE_PROD_API_SECRET=your_secret");
125 println!(" cargo run -- --config config/base.toml --config config/live-trading.toml");
126
127 Ok(())
128}Sourcepub fn validate(&self) -> Result<()>
pub fn validate(&self) -> Result<()>
Validate configuration values.
Checks that all configuration values are within acceptable ranges and meet business logic requirements.
§Errors
Returns an error if:
- Initial capital is not positive
- Commission rate is not between 0 and 1
- Max drawdown is not between 0 and 100