Skip to main content

nautilus_indicators/python/momentum/
amat.rs

1// -------------------------------------------------------------------------------------------------
2//  Copyright (C) 2015-2026 Nautech Systems Pty Ltd. All rights reserved.
3//  https://nautechsystems.io
4//
5//  Licensed under the GNU Lesser General Public License Version 3.0 (the "License");
6//  You may not use this file except in compliance with the License.
7//  You may obtain a copy of the License at https://www.gnu.org/licenses/lgpl-3.0.en.html
8//
9//  Unless required by applicable law or agreed to in writing, software
10//  distributed under the License is distributed on an "AS IS" BASIS,
11//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12//  See the License for the specific language governing permissions and
13//  limitations under the License.
14// -------------------------------------------------------------------------------------------------
15
16use nautilus_core::python::to_pyvalue_err;
17use nautilus_model::data::{Bar, QuoteTick, TradeTick};
18use pyo3::prelude::*;
19
20use crate::{
21    average::MovingAverageType, indicator::Indicator, momentum::amat::ArcherMovingAveragesTrends,
22};
23
24#[pymethods]
25#[pyo3_stub_gen::derive::gen_stub_pymethods]
26impl ArcherMovingAveragesTrends {
27    /// Creates a new `ArcherMovingAveragesTrends` instance.
28    #[new]
29    #[pyo3(signature = (fast_period, slow_period, signal_period, ma_type=None))]
30    #[must_use]
31    pub fn py_new(
32        fast_period: usize,
33        slow_period: usize,
34        signal_period: usize,
35        ma_type: Option<MovingAverageType>,
36    ) -> Self {
37        Self::new(fast_period, slow_period, signal_period, ma_type)
38    }
39
40    fn __repr__(&self) -> String {
41        format!(
42            "ArcherMovingAveragesTrends({},{},{},{})",
43            self.fast_period, self.slow_period, self.signal_period, self.ma_type
44        )
45    }
46
47    #[getter]
48    #[pyo3(name = "name")]
49    fn py_name(&self) -> String {
50        self.name()
51    }
52
53    #[getter]
54    #[pyo3(name = "fast_period")]
55    const fn py_fast_period(&self) -> usize {
56        self.fast_period
57    }
58
59    #[getter]
60    #[pyo3(name = "slow_period")]
61    const fn py_slow_period(&self) -> usize {
62        self.slow_period
63    }
64
65    #[getter]
66    #[pyo3(name = "signal_period")]
67    const fn py_signal_period(&self) -> usize {
68        self.signal_period
69    }
70
71    #[getter]
72    #[pyo3(name = "has_inputs")]
73    fn py_has_inputs(&self) -> bool {
74        self.has_inputs()
75    }
76
77    #[getter]
78    #[pyo3(name = "long_run")]
79    const fn py_long_run(&self) -> bool {
80        self.long_run
81    }
82
83    #[getter]
84    #[pyo3(name = "short_run")]
85    const fn py_short_run(&self) -> bool {
86        self.short_run
87    }
88
89    #[getter]
90    #[pyo3(name = "initialized")]
91    const fn py_initialized(&self) -> bool {
92        self.initialized
93    }
94
95    /// Updates the indicator with a new raw price value.
96    #[pyo3(name = "update_raw")]
97    fn py_update_raw(&mut self, close: f64) {
98        self.update_raw(close);
99    }
100
101    #[pyo3(name = "handle_quote_tick")]
102    fn py_handle_quote_tick(&mut self, quote: &QuoteTick) -> PyResult<()> {
103        self.handle_quote(quote).map_err(to_pyvalue_err)
104    }
105
106    #[pyo3(name = "handle_trade_tick")]
107    fn py_handle_trade_tick(&mut self, trade: &TradeTick) {
108        self.handle_trade(trade);
109    }
110
111    #[pyo3(name = "handle_bar")]
112    fn py_handle_bar(&mut self, bar: &Bar) {
113        self.handle_bar(bar);
114    }
115
116    #[pyo3(name = "reset")]
117    fn py_reset(&mut self) {
118        self.reset();
119    }
120}