Skip to main content

sandbox_quant/market_data/
price_store.rs

1use std::collections::BTreeMap;
2
3use crate::domain::instrument::Instrument;
4use crate::execution::price_source::PriceSource;
5
6#[derive(Debug, Clone, Default, PartialEq)]
7pub struct PriceStore {
8    prices: BTreeMap<Instrument, f64>,
9}
10
11impl PriceStore {
12    pub fn set_price(&mut self, instrument: Instrument, price: f64) {
13        if price > f64::EPSILON {
14            self.prices.insert(instrument, price);
15        }
16    }
17
18    pub fn snapshot(&self) -> Vec<(Instrument, f64)> {
19        self.prices
20            .iter()
21            .map(|(instrument, price)| (instrument.clone(), *price))
22            .collect()
23    }
24}
25
26impl PriceSource for PriceStore {
27    fn current_price(&self, instrument: &Instrument) -> Option<f64> {
28        self.prices.get(instrument).copied()
29    }
30}