Skip to content

Commit bce6301

Browse files
committed
feat(config): add configurable max_slippage_bps to ExecutionConfig
- Add max_slippage_bps field with serde default of 50.0 bps (0.5%) - Add validation: is_finite(), > 0.0, <= 500.0 bps (5% max) - Prevents NaN/Infinity configuration values
1 parent 0044171 commit bce6301

1 file changed

Lines changed: 29 additions & 0 deletions

File tree

rust/common/src/config.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,13 @@ pub struct ExecutionConfig {
108108
pub retry_attempts: u32,
109109
pub retry_delay_ms: u64,
110110
pub paper_trading: bool,
111+
/// Maximum allowed slippage in basis points (default: 50.0 = 0.5%)
112+
#[serde(default = "default_max_slippage_bps")]
113+
pub max_slippage_bps: f64,
114+
}
115+
116+
fn default_max_slippage_bps() -> f64 {
117+
50.0 // 50 basis points = 0.5%
111118
}
112119

113120
impl ExecutionConfig {
@@ -137,6 +144,28 @@ impl ExecutionConfig {
137144
));
138145
}
139146

147+
// Validate max_slippage_bps: must be finite, positive and <= 500 bps (5%)
148+
if !self.max_slippage_bps.is_finite() {
149+
return Err(TradingError::Configuration(
150+
"max_slippage_bps must be a finite number (not NaN or Infinity)".to_string()
151+
));
152+
}
153+
154+
if self.max_slippage_bps <= 0.0 {
155+
return Err(TradingError::Configuration(
156+
"max_slippage_bps must be positive".to_string()
157+
));
158+
}
159+
160+
if self.max_slippage_bps > 500.0 {
161+
return Err(TradingError::Configuration(
162+
format!(
163+
"max_slippage_bps ({}) exceeds maximum allowed (500 bps = 5%)",
164+
self.max_slippage_bps
165+
)
166+
));
167+
}
168+
140169
Ok(())
141170
}
142171

0 commit comments

Comments
 (0)