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
19impl PriceSource for PriceStore {
20    fn current_price(&self, instrument: &Instrument) -> Option<f64> {
21        self.prices.get(instrument).copied()
22    }
23}