Skip to main content

parse_decimal_or_warn

Function parse_decimal_or_warn 

Source
pub fn parse_decimal_or_warn(value: f64, field_name: &str) -> Decimal
Expand description

Convert f64 to Decimal, logging a warning if conversion fails (NaN/Inf).

Returns Decimal::ZERO for invalid values. This is acceptable because:

  • IB’s API should never return NaN/Inf for prices, quantities, or commissions
  • If it does, something is fundamentally broken and the warning log surfaces it
  • Callers processing trades in bulk shouldn’t abort on one corrupted record

For stricter handling, callers can check for zero in critical fields.