Skip to main content

wickra_embed_core/
traits.rs

1//! The [`Indicator`] contract — the same streaming state machine `wickra-core`
2//! uses, narrowed to a scalar `f64` output and no allocation.
3
4/// A streaming technical indicator.
5///
6/// The contract mirrors `wickra-core`'s trait so a no-alloc indicator here is a
7/// drop-in behavioural twin of its std counterpart:
8///
9/// - [`update`](Indicator::update) is called once per input point and is O(1) in
10///   the series length. It returns `None` while the indicator is still warming
11///   up and `Some(value)` once a defined value exists.
12/// - [`reset`](Indicator::reset) clears all state, leaving the indicator exactly
13///   as freshly constructed.
14///
15/// The associated [`Input`](Indicator::Input) is `Copy` (a price `f64` or a
16/// [`Candle`](crate::Candle)) so the update path never clones or allocates.
17pub trait Indicator {
18    /// Type of one input data point (`f64` for a price, [`Candle`](crate::Candle)
19    /// for an OHLC bar).
20    type Input: Copy;
21
22    /// Feed one new data point in and return the freshly computed value, or
23    /// `None` while still warming up.
24    fn update(&mut self, input: Self::Input) -> Option<f64>;
25
26    /// Reset all internal state, leaving the indicator equivalent to a freshly
27    /// constructed instance with the same parameters.
28    fn reset(&mut self);
29
30    /// Number of inputs required before the first non-`None` output.
31    fn warmup_period(&self) -> usize;
32
33    /// Whether the indicator has produced at least one value since construction
34    /// or the last [`reset`](Indicator::reset).
35    fn is_ready(&self) -> bool;
36
37    /// Stable, human-readable indicator name.
38    fn name(&self) -> &'static str;
39}