Skip to main content

nautilus_indicators/python/volatility/
fuzzy.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    indicator::Indicator,
21    volatility::fuzzy::{
22        CandleBodySize, CandleDirection, CandleSize, CandleWickSize, FuzzyCandle, FuzzyCandlesticks,
23    },
24};
25
26#[pymethods]
27#[pyo3_stub_gen::derive::gen_stub_pymethods]
28impl FuzzyCandle {
29    #[new]
30    #[must_use]
31    pub const fn py_new(
32        direction: CandleDirection,
33        size: CandleSize,
34        body_size: CandleBodySize,
35        upper_wick_size: CandleWickSize,
36        lower_wick_size: CandleWickSize,
37    ) -> Self {
38        Self::new(direction, size, body_size, upper_wick_size, lower_wick_size)
39    }
40
41    fn __repr__(&self) -> String {
42        format!(
43            "FuzzyCandle({},{},{},{},{})",
44            self.direction, self.size, self.body_size, self.upper_wick_size, self.lower_wick_size
45        )
46    }
47
48    #[getter]
49    #[pyo3(name = "direction")]
50    const fn py_direction(&self) -> CandleDirection {
51        self.direction
52    }
53
54    #[getter]
55    #[pyo3(name = "size")]
56    const fn py_size(&self) -> CandleSize {
57        self.size
58    }
59
60    #[getter]
61    #[pyo3(name = "body_size")]
62    const fn py_body_size(&self) -> CandleBodySize {
63        self.body_size
64    }
65
66    #[getter]
67    #[pyo3(name = "upper_wick_size")]
68    const fn py_upper_wick_size(&self) -> CandleWickSize {
69        self.upper_wick_size
70    }
71
72    #[getter]
73    #[pyo3(name = "lower_wick_size")]
74    const fn py_lower_wick_size(&self) -> CandleWickSize {
75        self.lower_wick_size
76    }
77}
78
79#[pymethods]
80#[pyo3_stub_gen::derive::gen_stub_pymethods]
81impl FuzzyCandlesticks {
82    /// Creates a new `FuzzyCandle` instance.
83    #[new]
84    #[must_use]
85    pub fn py_new(
86        period: usize,
87        threshold1: f64,
88        threshold2: f64,
89        threshold3: f64,
90        threshold4: f64,
91    ) -> Self {
92        Self::new(period, threshold1, threshold2, threshold3, threshold4)
93    }
94
95    fn __repr__(&self) -> String {
96        format!(
97            "FuzzyCandlesticks({},{},{},{},{})",
98            self.period, self.threshold1, self.threshold2, self.threshold3, self.threshold4
99        )
100    }
101
102    #[getter]
103    #[pyo3(name = "name")]
104    fn py_name(&self) -> String {
105        self.name()
106    }
107
108    #[getter]
109    #[pyo3(name = "period")]
110    const fn py_period(&self) -> usize {
111        self.period
112    }
113
114    #[getter]
115    #[pyo3(name = "threshold1")]
116    const fn py_threshold1(&self) -> f64 {
117        self.threshold1
118    }
119
120    #[getter]
121    #[pyo3(name = "threshold2")]
122    const fn py_threshold2(&self) -> f64 {
123        self.threshold2
124    }
125
126    #[getter]
127    #[pyo3(name = "threshold3")]
128    const fn py_threshold3(&self) -> f64 {
129        self.threshold3
130    }
131
132    #[getter]
133    #[pyo3(name = "threshold4")]
134    const fn py_threshold4(&self) -> f64 {
135        self.threshold4
136    }
137
138    #[getter]
139    #[pyo3(name = "has_inputs")]
140    fn py_has_inputs(&self) -> bool {
141        self.has_inputs()
142    }
143
144    #[getter]
145    #[pyo3(name = "value")]
146    const fn py_value(&self) -> FuzzyCandle {
147        self.value
148    }
149
150    #[getter]
151    #[pyo3(name = "vector")]
152    fn py_vector(&self) -> Vec<i32> {
153        self.vector.clone()
154    }
155
156    #[getter]
157    #[pyo3(name = "initialized")]
158    const fn py_initialized(&self) -> bool {
159        self.initialized
160    }
161
162    #[pyo3(name = "update_raw")]
163    fn py_update_raw(&mut self, open: f64, high: f64, low: f64, close: f64) {
164        self.update_raw(open, high, low, close);
165    }
166
167    #[pyo3(name = "handle_bar")]
168    fn py_handle_bar(&mut self, bar: &Bar) {
169        self.handle_bar(bar);
170    }
171
172    #[pyo3(name = "reset")]
173    fn py_reset(&mut self) {
174        self.reset();
175    }
176}