sandbox_quant/market_data/
service.rs1use crate::domain::instrument::Instrument;
2use crate::domain::market::Market;
3use crate::error::exchange_error::ExchangeError;
4use crate::exchange::facade::ExchangeFacade;
5use crate::execution::price_source::PriceSource;
6use crate::market_data::price_store::PriceStore;
7
8#[derive(Debug, Default)]
9pub struct MarketDataService;
10
11impl MarketDataService {
12 pub fn apply_price(&self, store: &mut PriceStore, instrument: Instrument, price: f64) {
18 store.set_price(instrument, price);
19 }
20
21 pub fn refresh_price<E: ExchangeFacade<Error = ExchangeError>>(
22 &self,
23 exchange: &E,
24 store: &mut PriceStore,
25 instrument: Instrument,
26 market: Market,
27 ) -> Result<f64, ExchangeError> {
28 let price = exchange.load_last_price(&instrument, market)?;
29 store.set_price(instrument, price);
30 Ok(price)
31 }
32
33 pub fn current_price(&self, store: &impl PriceSource, instrument: &Instrument) -> Option<f64> {
34 store.current_price(instrument)
35 }
36}