Skip to main content

parse_decimal_or_warn

Function parse_decimal_or_warn 

Source
pub fn parse_decimal_or_warn(value: f64, field_name: impl Display) -> 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

Where zero would be read as a real value, such as an ended order’s fill, use try_decimal_or_warn and keep it unknown instead.