{"record":{"id":"e6b3fe084ab09983","repo":"nautechsystems/nautilus_trader","slug":"derive-label-cannot-be-represented-as-f64","errorCode":null,"errorMessage":"Derive {label} cannot be represented as f64","messagePattern":"Derive (.+?) cannot be represented as f64","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/adapters/derive/src/websocket/parse.rs","lineNumber":708,"sourceCode":"///\n/// Returns `Ok(None)` when the ticker does not carry option pricing.\n///\n/// # Errors\n///\n/// Returns an error when the ticker timestamp is negative or overflows.\npub fn parse_option_greeks(\n    msg: &DeriveTickerMsg,\n    ts_init: UnixNanos,\n) -> anyhow::Result<Option<OptionGreeks>> {\n    let Some(pricing) = msg.data.option_pricing() else {\n        return Ok(None);\n    };\n    let instrument_id = msg.data.instrument_id();\n    let ts_event = ticker_ts_event(msg.data.timestamp())?;\n    let to_f64 = |label: &str, value: rust_decimal::Decimal| {\n        value\n            .to_f64()\n            .ok_or_else(|| anyhow::anyhow!(\"Derive {label} cannot be represented as f64\"))\n    };\n\n    Ok(Some(OptionGreeks {\n        instrument_id,\n        convention: GreeksConvention::BlackScholes,\n        greeks: OptionGreekValues {\n            delta: to_f64(\"delta\", pricing.delta)?,\n            gamma: to_f64(\"gamma\", pricing.gamma)?,\n            vega: to_f64(\"vega\", pricing.vega)?,\n            theta: to_f64(\"theta\", pricing.theta)?,\n            rho: to_f64(\"rho\", pricing.rho)?,\n        },\n        mark_iv: Some(to_f64(\"iv\", pricing.iv)?),\n        bid_iv: Some(to_f64(\"bid_iv\", pricing.bid_iv)?),\n        ask_iv: Some(to_f64(\"ask_iv\", pricing.ask_iv)?),\n        underlying_price: Some(to_f64(\"forward_price\", pricing.forward_price)?),\n        open_interest: msg\n            .data","sourceCodeStart":690,"sourceCodeEnd":726,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/derive/src/websocket/parse.rs#L690-L726","documentation":"parse_option_greeks converts rust_decimal::Decimal greek values (delta, gamma, etc.) to f64 for OptionGreeks. If a Decimal cannot be represented as f64 (e.g. NaN or infinite decimal values that to_f64 rejects), this error is thrown naming the greek label.","triggerScenarios":"A Derive option ticker payload with option_pricing whose greek decimal is NaN or not convertible to f64; the closure to_f64 fails for any greek field being mapped.","commonSituations":"Venue sending NaN greeks for illiquid/expiring options; edge-case decimals outside f64 range; instruments without valid pricing models on Derive's side.","solutions":["Skip/ignore the greeks update for that instrument when values are non-finite","Sanitize incoming decimals (reject NaN) before parsing","Check whether Derive is emitting NaN for the specific instrument and filter those ticks"],"exampleFix":"// before\nlet to_f64 = |label: &str, value: Decimal| value.to_f64().ok_or_else(|| anyhow!(\"Derive {label} cannot be represented as f64\"));\n// after (skip invalid instead of failing the whole tick)\nlet to_f64 = |label: &str, value: Decimal| value.to_f64().filter(|v| v.is_finite());\nif greeks.iter().any(|(l, v)| to_f64(l, *v).is_none()) { return Ok(None); }","handlingStrategy":"try-catch","validationCode":"fn greeks_are_finite(v: &rust_decimal::Decimal) -> bool { v.is_finite() && v.to_f64().map(|f| f.is_finite()).unwrap_or(false) }","typeGuard":"fn to_f64_checked(v: rust_decimal::Decimal) -> Option<f64> { v.to_f64().filter(|f| f.is_finite()) }","tryCatchPattern":"match parse_option_greeks(&msg) { Ok(Some(g)) => apply(g), Ok(None) => {}, Err(e) if e.to_string().contains(\"cannot be represented as f64\") => warn!(\"skipping non-finite greeks: {e}\"), Err(e) => return Err(e) }","preventionTips":["Sanitize decimals for NaN/non-finite values before conversion","Filter greek ticks from illiquid/expiring instruments","Never let a single bad tick break the whole WS handler — degrade gracefully"],"tags":["rust","websocket","parsing","numeric"],"backgroundTag":"unexpected-api-response-shape","analyzedSha":"18893faf8b356be3320add8de2f861b0b647cf06","analyzedAt":"2026-09-08T20:49:34.690Z","contentChangedAt":"2026-09-08T20:49:34.690Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}