Skip to main content

nautilus_indicators/python/average/
vwap.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::{average::vwap::VolumeWeightedAveragePrice, indicator::Indicator};
20
21#[pymethods]
22#[pyo3_stub_gen::derive::gen_stub_pymethods]
23impl VolumeWeightedAveragePrice {
24    /// Creates a new `VolumeWeightedAveragePrice` instance.
25    #[new]
26    #[must_use]
27    pub const fn py_new() -> Self {
28        Self::new()
29    }
30
31    fn __repr__(&self) -> String {
32        "VolumeWeightedAveragePrice".to_string()
33    }
34
35    #[getter]
36    #[pyo3(name = "name")]
37    fn py_name(&self) -> String {
38        self.name()
39    }
40
41    #[getter]
42    #[pyo3(name = "has_inputs")]
43    fn py_has_inputs(&self) -> bool {
44        self.has_inputs()
45    }
46
47    #[getter]
48    #[pyo3(name = "value")]
49    const fn py_value(&self) -> f64 {
50        self.value
51    }
52
53    #[getter]
54    #[pyo3(name = "initialized")]
55    const fn py_initialized(&self) -> bool {
56        self.initialized
57    }
58
59    #[pyo3(name = "handle_bar")]
60    fn py_handle_bar(&mut self, bar: &Bar) {
61        self.py_update_raw(
62            (&bar.close).into(),
63            (&bar.volume).into(),
64            bar.ts_init.as_f64(),
65        );
66    }
67
68    #[pyo3(name = "reset")]
69    fn py_reset(&mut self) {
70        self.reset();
71    }
72
73    #[pyo3(name = "update_raw")]
74    fn py_update_raw(&mut self, value: f64, volume: f64, ts: f64) {
75        self.update_raw(value, volume, ts);
76    }
77}