Skip to main content

quantwave_core/
traits.rs

1/// The core trait for streaming indicators.
2/// Every indicator maintains an internal state and processes data points one by one.
3pub trait Next<Input> {
4    type Output;
5
6    /// Process the next input and return the updated output.
7    fn next(&mut self, input: Input) -> Self::Output;
8}
9
10/// A trait for algorithms that smooth a series of values (e.g., SMA, EMA).
11/// This allows indicators like SuperTrend or Keltner Channels to be generic over their MA type.
12pub trait SmoothingAlgorithm: Next<f64, Output = f64> + Clone + Send + Sync {}
13
14/// A trait for indicator configurations that can build their respective streaming state machines.
15pub trait IndicatorConfig {
16    type Indicator: Next<f64>;
17
18    /// Build a new instance of the indicator state machine.
19    fn build(&self) -> Self::Indicator;
20}
21
22/// Blanket implementation for types that satisfy the SmoothingAlgorithm requirements.
23impl<T> SmoothingAlgorithm for T where T: Next<f64, Output = f64> + Clone + Send + Sync {}