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