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