nautilus_indicators/python/momentum/
swings.rs

1// -------------------------------------------------------------------------------------------------
2//  Copyright (C) 2015-2025 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, QuoteTick, TradeTick};
17use pyo3::prelude::*;
18
19use crate::{indicator::Indicator, momentum::swings::Swings};
20
21#[pymethods]
22impl Swings {
23    #[new]
24    #[must_use]
25    pub fn py_new(period: usize) -> Self {
26        Self::new(period)
27    }
28
29    fn __repr__(&self) -> String {
30        format!("Swings({})", self.period)
31    }
32
33    #[getter]
34    #[pyo3(name = "name")]
35    fn py_name(&self) -> String {
36        self.name()
37    }
38
39    #[getter]
40    #[pyo3(name = "period")]
41    const fn py_period(&self) -> usize {
42        self.period
43    }
44
45    #[getter]
46    #[pyo3(name = "has_inputs")]
47    fn py_has_inputs(&self) -> bool {
48        self.has_inputs()
49    }
50
51    #[getter]
52    #[pyo3(name = "direction")]
53    const fn py_direction(&self) -> i64 {
54        self.direction
55    }
56
57    #[getter]
58    #[pyo3(name = "changed")]
59    const fn py_changed(&self) -> bool {
60        self.changed
61    }
62
63    #[getter]
64    #[pyo3(name = "high_datetime")]
65    const fn py_high_datetime(&self) -> f64 {
66        self.high_datetime
67    }
68
69    #[getter]
70    #[pyo3(name = "low_datetime")]
71    const fn py_low_datetime(&self) -> f64 {
72        self.low_datetime
73    }
74
75    #[getter]
76    #[pyo3(name = "high_price")]
77    const fn py_high_price(&self) -> f64 {
78        self.high_price
79    }
80
81    #[getter]
82    #[pyo3(name = "low_price")]
83    const fn py_low_price(&self) -> f64 {
84        self.low_price
85    }
86
87    #[getter]
88    #[pyo3(name = "length")]
89    const fn py_length(&self) -> usize {
90        self.length
91    }
92
93    #[getter]
94    #[pyo3(name = "duration")]
95    const fn py_duration(&self) -> usize {
96        self.duration
97    }
98
99    #[getter]
100    #[pyo3(name = "since_high")]
101    const fn py_since_high(&self) -> usize {
102        self.since_high
103    }
104
105    #[getter]
106    #[pyo3(name = "since_low")]
107    const fn py_since_low(&self) -> usize {
108        self.since_low
109    }
110
111    #[getter]
112    #[pyo3(name = "initialized")]
113    fn py_initialized(&self) -> bool {
114        self.initialized()
115    }
116
117    #[pyo3(name = "update_raw")]
118    fn py_update_raw(&mut self, high: f64, low: f64, timestamp: f64) {
119        self.update_raw(high, low, timestamp);
120    }
121
122    #[pyo3(name = "handle_quote_tick")]
123    const fn py_handle_quote_tick(&mut self, _quote: &QuoteTick) {
124        // Function body intentionally left blank.
125    }
126
127    #[pyo3(name = "handle_trade_tick")]
128    const fn py_handle_trade_tick(&mut self, _trade: &TradeTick) {
129        // Function body intentionally left blank.
130    }
131
132    #[pyo3(name = "handle_bar")]
133    fn py_handle_bar(&mut self, bar: &Bar) {
134        self.update_raw((&bar.high).into(), (&bar.low).into(), bar.ts_init.as_f64());
135    }
136
137    #[pyo3(name = "reset")]
138    fn py_reset(&mut self) {
139        self.reset();
140    }
141}