pub struct LifecycleRunner<I: Indicator + Clone> { /* private fields */ }Expand description
Wraps an Indicator + Clone so BarLifecycle::Open/BarLifecycle::Update events can be
replayed any number of times without permanently mutating state, and only
BarLifecycle::Confirmed/BarLifecycle::Correction commit a new checkpoint.
Implementations§
Source§impl<I: Indicator + Clone> LifecycleRunner<I>
impl<I: Indicator + Clone> LifecycleRunner<I>
pub fn new(indicator: I) -> Self
Sourcepub fn confirmed_indicator(&self) -> Option<&I>
pub fn confirmed_indicator(&self) -> Option<&I>
The indicator state as of the last confirmed/corrected bar (never a tentative
open/update). None before the first confirmation.
Sourcepub fn on_event(
&mut self,
event: BarLifecycle,
) -> Result<Option<IndicatorOutput>, LifecycleError>
pub fn on_event( &mut self, event: BarLifecycle, ) -> Result<Option<IndicatorOutput>, LifecycleError>
Processes one lifecycle event and returns the resulting output.
Open/Update always start from the last confirmed checkpoint (or a freshly reset
indicator if none exists yet) before applying bar, so repeated calls for the same
still-forming timestamp are idempotent and never stack on top of a prior tentative
application.
Confirmed for a new (strictly later, or first-ever) timestamp advances both checkpoints.
Confirmed or Correction for the same timestamp as the last confirmed bar replaces it:
the pre-bar checkpoint is restored and the revised bar is applied exactly once, instead of
stacking on top of the original bar’s effect. A Correction/out-of-order Confirmed for
any other timestamp is rejected with LifecycleError, since only single-level undo is
representable.