Skip to main content

nautilus_indicators/python/momentum/
kvo.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_model::data::Bar;
17use pyo3::prelude::*;
18
19use crate::{
20    average::MovingAverageType, indicator::Indicator, momentum::kvo::KlingerVolumeOscillator,
21};
22
23#[pymethods]
24#[pyo3_stub_gen::derive::gen_stub_pymethods]
25impl KlingerVolumeOscillator {
26    /// Creates a new `KlingerVolumeOscillator` instance.
27    #[new]
28    #[pyo3(signature = (fast_period, slow_period, signal_period, ma_type=None))]
29    #[must_use]
30    pub fn py_new(
31        fast_period: usize,
32        slow_period: usize,
33        signal_period: usize,
34        ma_type: Option<MovingAverageType>,
35    ) -> Self {
36        Self::new(fast_period, slow_period, signal_period, ma_type)
37    }
38
39    fn __repr__(&self) -> String {
40        format!(
41            "KlingerVolumeOscillator({},{},{},{})",
42            self.fast_period, self.slow_period, self.signal_period, self.ma_type
43        )
44    }
45
46    #[getter]
47    #[pyo3(name = "name")]
48    fn py_name(&self) -> String {
49        self.name()
50    }
51
52    #[getter]
53    #[pyo3(name = "fast_period")]
54    const fn py_fast_period(&self) -> usize {
55        self.fast_period
56    }
57
58    #[getter]
59    #[pyo3(name = "slow_period")]
60    const fn py_slow_period(&self) -> usize {
61        self.slow_period
62    }
63
64    #[getter]
65    #[pyo3(name = "signal_period")]
66    const fn py_signal_period(&self) -> usize {
67        self.signal_period
68    }
69
70    #[getter]
71    #[pyo3(name = "has_inputs")]
72    fn py_has_inputs(&self) -> bool {
73        self.has_inputs()
74    }
75
76    #[getter]
77    #[pyo3(name = "value")]
78    const fn py_value(&self) -> f64 {
79        self.value
80    }
81
82    #[getter]
83    #[pyo3(name = "initialized")]
84    const fn py_initialized(&self) -> bool {
85        self.initialized
86    }
87
88    #[pyo3(name = "update_raw")]
89    fn py_update_raw(&mut self, high: f64, low: f64, close: f64, volume: f64) {
90        self.update_raw(high, low, close, volume);
91    }
92
93    #[pyo3(name = "handle_bar")]
94    fn py_handle_bar(&mut self, bar: &Bar) {
95        self.handle_bar(bar);
96    }
97
98    #[pyo3(name = "reset")]
99    fn py_reset(&mut self) {
100        self.reset();
101    }
102}