Skip to main content

hypercall/rsm/unified_engine/
fill_metadata.rs

1use super::*;
2
3impl UnifiedEngine {
4    pub(super) fn attach_fill_underlying_notional(&self, fill: &mut Fill) {
5        fill.underlying_notional = resolve_fill_underlying_notional(
6            fill,
7            &self.ctx.spot_prices,
8            &self.ctx.deps.reference_prices,
9        );
10    }
11}
12
13pub(super) fn resolve_fill_underlying_notional(
14    fill: &Fill,
15    spot_prices: &HashMap<String, Decimal>,
16    reference_prices: &HashMap<String, f64>,
17) -> Option<Decimal> {
18    if fill.underlying_notional.is_some() {
19        return fill.underlying_notional;
20    }
21
22    let parsed = match ParsedSymbol::from_symbol(&fill.symbol) {
23        Ok(parsed) => parsed,
24        Err(_) if !hypercall_types::utils::is_option_symbol(&fill.symbol) => return None,
25        Err(err) => {
26            panic!(
27                "FILL_METADATA_FATAL: failed to parse option fill symbol {}: {}",
28                fill.symbol, err
29            );
30        }
31    };
32
33    let spot_price = spot_prices
34        .get(&parsed.underlying)
35        .copied()
36        .or_else(|| {
37            reference_prices
38                .get(&parsed.underlying)
39                .and_then(|price| Decimal::from_f64_retain(*price))
40        })
41        .unwrap_or_else(|| {
42            panic!(
43                "FILL_METADATA_FATAL: missing spot price for option fill {} underlying {}",
44                fill.symbol, parsed.underlying
45            )
46        });
47
48    if spot_price <= Decimal::ZERO {
49        panic!(
50            "FILL_METADATA_FATAL: invalid spot price {} for option fill {}",
51            spot_price, fill.symbol
52        );
53    }
54
55    let size_human = to_human_readable_decimal(&fill.symbol, fill.size);
56    Some(size_human.abs() * spot_price)
57}