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