fix(broker_gateway): safe cTrader volume conversion with overflow checks
The previous (quantity * 100_000.0) as i64 silently truncated fractional lots and could overflow on extreme values. Added convert_quantity_to_volume() that validates the result is finite, non-negative, and within i64 range, using round() instead of truncation. Includes 7 unit tests covering normal values, fractional rounding, overflow, negative, NaN, infinity, and zero edge cases. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -98,6 +98,7 @@ impl BrokerGatewayService {
|
||||
///
|
||||
/// Returns an error if the result is not finite, negative, or exceeds i64 range.
|
||||
/// Uses rounding to avoid silent truncation of fractional lots.
|
||||
#[cfg_attr(not(feature = "icmarkets"), allow(dead_code))]
|
||||
fn convert_quantity_to_volume(quantity: f64) -> Result<i64, Status> {
|
||||
let volume_f = quantity * 100_000.0;
|
||||
if !volume_f.is_finite() || volume_f < 0.0 || volume_f > i64::MAX as f64 {
|
||||
|
||||
Reference in New Issue
Block a user