nautilus_indicators/python/average/
vidya.rs1use nautilus_model::{
17 data::{Bar, QuoteTick, TradeTick},
18 enums::PriceType,
19};
20use pyo3::prelude::*;
21
22use crate::{
23 average::{vidya::VariableIndexDynamicAverage, MovingAverageType},
24 indicator::{Indicator, MovingAverage},
25};
26
27#[pymethods]
28impl VariableIndexDynamicAverage {
29 #[new]
30 #[pyo3(signature = (period, price_type=None, cmo_ma_type=None))]
31 #[must_use]
32 pub fn py_new(
33 period: usize,
34 price_type: Option<PriceType>,
35 cmo_ma_type: Option<MovingAverageType>,
36 ) -> Self {
37 Self::new(period, price_type, cmo_ma_type)
38 }
39
40 fn __repr__(&self) -> String {
41 format!(
42 "VariableIndexDynamicAverage({},{:?})",
43 self.period, self.price_type
44 )
45 }
46
47 #[getter]
48 #[pyo3(name = "name")]
49 fn py_name(&self) -> String {
50 self.name()
51 }
52
53 #[getter]
54 #[pyo3(name = "period")]
55 const fn py_period(&self) -> usize {
56 self.period
57 }
58
59 #[getter]
60 #[pyo3(name = "count")]
61 fn py_count(&self) -> usize {
62 self.count()
63 }
64
65 #[getter]
66 #[pyo3(name = "alpha")]
67 const fn py_alpha(&self) -> f64 {
68 self.alpha
69 }
70
71 #[getter]
72 #[pyo3(name = "has_inputs")]
73 fn py_has_inputs(&self) -> bool {
74 self.has_inputs()
75 }
76
77 #[getter]
78 #[pyo3(name = "initialized")]
79 const fn py_initialized(&self) -> bool {
80 self.initialized
81 }
82
83 #[getter]
84 #[pyo3(name = "cmo_pct")]
85 const fn py_cmo_pct(&self) -> f64 {
86 self.cmo_pct
87 }
88
89 #[getter]
90 #[pyo3(name = "value")]
91 const fn py_value(&self) -> f64 {
92 self.value
93 }
94
95 #[pyo3(name = "handle_quote_tick")]
96 fn py_handle_quote_tick(&mut self, quote: &QuoteTick) {
97 self.py_update_raw(quote.extract_price(self.price_type).into());
98 }
99
100 #[pyo3(name = "handle_trade_tick")]
101 fn py_handle_trade_tick(&mut self, trade: &TradeTick) {
102 self.update_raw((&trade.price).into());
103 }
104
105 #[pyo3(name = "handle_bar")]
106 fn py_handle_bar(&mut self, bar: &Bar) {
107 self.update_raw((&bar.close).into());
108 }
109
110 #[pyo3(name = "reset")]
111 fn py_reset(&mut self) {
112 self.reset();
113 }
114
115 #[pyo3(name = "update_raw")]
116 fn py_update_raw(&mut self, value: f64) {
117 self.update_raw(value);
118 }
119}