Skip to main content

VeloraConfig

Struct VeloraConfig 

Source
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: EngineConfig

Engine configuration Env: VELORA_ENGINE_*

§risk: RiskConfig

Risk management configuration Env: VELORA_RISK_*

§logging: LoggingConfig

Logging configuration Env: VELORA_LOGGING_*

§database: DatabaseConfig

Database configuration Env: VELORA_DATABASE_*

Implementations§

Source§

impl VeloraConfig

Source§

impl VeloraConfig

Source

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?
examples/config_loading.rs (line 18)
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}
Source

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)
  1. Environment variables (VELORA_*)
  2. Last config file in the list
  3. …
  4. First config file in the list
  5. 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?
examples/config_loading.rs (line 33)
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}
Source

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?
examples/config_loading.rs (lines 49-53)
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}
Source

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

Trait Implementations§

Source§

impl Clone for VeloraConfig

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for VeloraConfig

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for VeloraConfig

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for VeloraConfig

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for VeloraConfig

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more