Skip to main content

quantwave_core/indicators/
talib_wrapper.rs

1//! Macros for the macro-generated, TA-Lib-compatible streaming indicators.
2//! Struct names intentionally mirror TA-Lib identifiers (`CDLDOJI`, `HT_SINE`, …).
3//!
4//! Everything here is native. The `native_cdl!` macro that wrapped
5//! `talib_rs::pattern::*` at runtime, and the eleven never-invoked `talib_*`
6//! macros beside it, were removed once all 60 candlestick patterns were ported
7//! to native streaming implementations under `indicators::patterns`.
8#![allow(non_camel_case_types)]
9
10/// O(1) unary pointwise transform — no history buffer.
11#[macro_export]
12macro_rules! native_pointwise_1 {
13    ($name:ident, $op:expr) => {
14        #[derive(Debug, Clone, Default)]
15        pub struct $name;
16
17        impl $name {
18            pub fn new() -> Self {
19                Self
20            }
21        }
22
23        impl $crate::traits::Next<f64> for $name {
24            type Output = f64;
25
26            fn next(&mut self, input: f64) -> Self::Output {
27                ($op)(input)
28            }
29
30            fn next_batch(&mut self, inputs: &[f64]) -> Vec<Self::Output>
31            where
32                f64: Copy,
33            {
34                inputs.iter().map(|&x| ($op)(x)).collect()
35            }
36        }
37    };
38}
39
40/// O(1) binary element-wise operator.
41#[macro_export]
42macro_rules! native_binary_2 {
43    ($name:ident, $op:expr) => {
44        #[derive(Debug, Clone, Default)]
45        pub struct $name;
46
47        impl $name {
48            pub fn new() -> Self {
49                Self
50            }
51        }
52
53        impl $crate::traits::Next<(f64, f64)> for $name {
54            type Output = f64;
55
56            fn next(&mut self, (a, b): (f64, f64)) -> Self::Output {
57                ($op)(a, b)
58            }
59
60            fn next_batch(&mut self, inputs: &[(f64, f64)]) -> Vec<Self::Output>
61            where
62                (f64, f64): Copy,
63            {
64                inputs.iter().map(|&(a, b)| ($op)(a, b)).collect()
65            }
66        }
67    };
68}