diff --git a/crates/idx-core/src/api/msn/map.rs b/crates/idx-core/src/api/msn/map.rs index d2a51f9..b0f445f 100644 --- a/crates/idx-core/src/api/msn/map.rs +++ b/crates/idx-core/src/api/msn/map.rs @@ -33,7 +33,7 @@ pub(super) fn parse_quote(symbol: &str, quotes: &[MsnQuote]) -> Result Option { (value.is_finite() && (0.0..=MAX_PRICE).contains(&value)).then(|| value.round() as i64) } +/// A price change can be negative; same bound on its size. +fn round_change(value: f64) -> Option { + (value.is_finite() && value.abs() <= MAX_PRICE).then(|| value.round() as i64) +} + fn round_u64(value: Option) -> Option { value.and_then(|number| { if !number.is_finite() || number.is_sign_negative() { @@ -679,7 +684,7 @@ pub(super) fn parse_screener_results(raw: &RawScreenerResponse) -> Result = + serde_json::from_str(r#"[{"symbol":"BBCA","price":100.0,"priceChange":-5.0}]"#) + .unwrap(); + assert_eq!(parse_quote("BBCA.JK", &raw).unwrap().change, Some(-5)); + } + #[test] fn parses_news_fixture_items() { let raw: RawNewsFeed =