Skip to main content

nautilus_indicators/python/book/
imbalance.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::{orderbook::OrderBook, types::Quantity};
17use pyo3::prelude::*;
18
19use crate::{book::imbalance::BookImbalanceRatio, indicator::Indicator};
20
21#[pymethods]
22#[pyo3_stub_gen::derive::gen_stub_pymethods]
23impl BookImbalanceRatio {
24    /// Creates a new `BookImbalanceRatio` instance.
25    #[new]
26    const fn py_new() -> Self {
27        Self::new()
28    }
29
30    fn __repr__(&self) -> String {
31        self.to_string()
32    }
33
34    #[getter]
35    #[pyo3(name = "name")]
36    fn py_name(&self) -> String {
37        self.name()
38    }
39
40    #[getter]
41    #[pyo3(name = "count")]
42    const fn py_count(&self) -> usize {
43        self.count
44    }
45
46    #[getter]
47    #[pyo3(name = "value")]
48    const fn py_value(&self) -> f64 {
49        self.value
50    }
51
52    #[getter]
53    #[pyo3(name = "has_inputs")]
54    fn py_has_inputs(&self) -> bool {
55        self.has_inputs()
56    }
57
58    #[getter]
59    #[pyo3(name = "initialized")]
60    const fn py_initialized(&self) -> bool {
61        self.initialized
62    }
63
64    #[pyo3(name = "handle_book")]
65    fn py_handle_book(&mut self, book: &OrderBook) {
66        self.handle_book(book);
67    }
68
69    #[pyo3(name = "update")]
70    #[pyo3(signature = (best_bid=None, best_ask=None))]
71    fn py_update(&mut self, best_bid: Option<Quantity>, best_ask: Option<Quantity>) {
72        self.update(best_bid, best_ask);
73    }
74
75    #[pyo3(name = "reset")]
76    fn py_reset(&mut self) {
77        self.reset();
78    }
79}