qs_backtest/strategy/
context.rs1use chrono::NaiveDateTime;
4use qs_core::TradeEngine;
5
6use super::{HistoricalObservationView, HistoricalSeriesView};
7
8#[derive(Clone, Copy)]
10pub struct StrategyContext<'a> {
11 observed_through: NaiveDateTime,
12 series: &'a dyn HistoricalSeriesView,
13 observations: &'a dyn HistoricalObservationView,
14 engine: &'a TradeEngine,
15 warmup_complete: bool,
16}
17
18impl<'a> StrategyContext<'a> {
19 pub fn new(
20 observed_through: NaiveDateTime,
21 series: &'a dyn HistoricalSeriesView,
22 observations: &'a dyn HistoricalObservationView,
23 engine: &'a TradeEngine,
24 warmup_complete: bool,
25 ) -> Self {
26 Self {
27 observed_through,
28 series,
29 observations,
30 engine,
31 warmup_complete,
32 }
33 }
34
35 pub fn observed_through(self) -> NaiveDateTime {
36 self.observed_through
37 }
38
39 pub fn series(self) -> &'a dyn HistoricalSeriesView {
40 self.series
41 }
42
43 pub fn observations(self) -> &'a dyn HistoricalObservationView {
44 self.observations
45 }
46
47 pub fn engine(self) -> &'a TradeEngine {
48 self.engine
49 }
50
51 pub fn warmup_complete(self) -> bool {
52 self.warmup_complete
53 }
54}