Skip to main content

nautilus_indicators/python/momentum/
cmo.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::cmo::ChandeMomentumOscillator,
22};
23
24#[pymethods]
25#[pyo3_stub_gen::derive::gen_stub_pymethods]
26impl ChandeMomentumOscillator {
27    /// Creates a new `ChandeMomentumOscillator` instance.
28    #[new]
29    #[pyo3(signature = (period, ma_type=None))]
30    #[must_use]
31    pub fn py_new(period: usize, ma_type: Option<MovingAverageType>) -> Self {
32        Self::new(period, ma_type)
33    }
34
35    #[getter]
36    #[pyo3(name = "name")]
37    fn py_name(&self) -> String {
38        self.name()
39    }
40
41    #[getter]
42    #[pyo3(name = "period")]
43    const fn py_period(&self) -> usize {
44        self.period
45    }
46
47    #[getter]
48    #[pyo3(name = "has_inputs")]
49    fn py_has_inputs(&self) -> bool {
50        self.has_inputs()
51    }
52
53    #[getter]
54    #[pyo3(name = "count")]
55    const fn py_count(&self) -> usize {
56        self.count
57    }
58
59    #[getter]
60    #[pyo3(name = "value")]
61    const fn py_value(&self) -> f64 {
62        self.value
63    }
64
65    #[getter]
66    #[pyo3(name = "initialized")]
67    const fn py_initialized(&self) -> bool {
68        self.initialized
69    }
70
71    #[pyo3(name = "update_raw")]
72    fn py_update_raw(&mut self, close: f64) {
73        self.update_raw(close);
74    }
75
76    #[pyo3(name = "handle_quote_tick")]
77    fn py_handle_quote_tick(&mut self, quote: &QuoteTick) -> PyResult<()> {
78        self.handle_quote(quote).map_err(to_pyvalue_err)
79    }
80
81    #[pyo3(name = "handle_trade_tick")]
82    fn py_handle_trade_tick(&mut self, trade: &TradeTick) {
83        self.handle_trade(trade);
84    }
85
86    #[pyo3(name = "handle_bar")]
87    fn py_handle_bar(&mut self, bar: &Bar) {
88        self.handle_bar(bar);
89    }
90
91    #[pyo3(name = "reset")]
92    fn py_reset(&mut self) {
93        self.reset();
94    }
95
96    fn __repr__(&self) -> String {
97        format!("ChandeMomentumOscillator({})", self.period)
98    }
99}