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::{
20    average::vwap::VolumeWeightedAveragePrice, indicator::Indicator, python::float_precision,
21};
22
23#[pymethods]
24#[pyo3_stub_gen::derive::gen_stub_pymethods]
25impl VolumeWeightedAveragePrice {
26    /// Volume-weighted average price.
27    #[new]
28    #[must_use]
29    pub const fn py_new() -> Self {
30        Self::new()
31    }
32
33    fn __repr__(&self) -> String {
34        "VolumeWeightedAveragePrice".to_string()
35    }
36
37    #[getter]
38    #[pyo3(name = "name")]
39    fn py_name(&self) -> String {
40        self.name()
41    }
42
43    #[getter]
44    #[pyo3(name = "has_inputs")]
45    fn py_has_inputs(&self) -> bool {
46        self.has_inputs()
47    }
48
49    #[getter]
50    #[pyo3(name = "value")]
51    const fn py_value(&self) -> f64 {
52        self.value
53    }
54
55    #[getter]
56    #[pyo3(name = "initialized")]
57    const fn py_initialized(&self) -> bool {
58        self.initialized
59    }
60
61    #[pyo3(name = "handle_bar")]
62    fn py_handle_bar(&mut self, bar: &Bar) -> PyResult<()> {
63        float_precision::check_bar(bar)?;
64        float_precision::check_bar_volume(bar)?;
65        self.handle_bar(bar);
66        Ok(())
67    }
68
69    #[pyo3(name = "reset")]
70    fn py_reset(&mut self) {
71        self.reset();
72    }
73
74    /// Adds a price and nonnegative volume to the current manually reset window.
75    /// Non-finite inputs and negative volume leave state unchanged.
76    #[pyo3(name = "update_raw")]
77    fn py_update_raw(&mut self, value: f64, volume: f64) {
78        self.update_raw(value, volume);
79    }
80}