nautilus_indicators/python/book/
imbalance.rs

1// -------------------------------------------------------------------------------------------------
2//  Copyright (C) 2015-2025 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]
22impl BookImbalanceRatio {
23    #[new]
24    const fn py_new() -> Self {
25        Self::new()
26    }
27
28    fn __repr__(&self) -> String {
29        self.to_string()
30    }
31
32    #[getter]
33    #[pyo3(name = "name")]
34    fn py_name(&self) -> String {
35        self.name()
36    }
37
38    #[getter]
39    #[pyo3(name = "count")]
40    const fn py_count(&self) -> usize {
41        self.count
42    }
43
44    #[getter]
45    #[pyo3(name = "value")]
46    const fn py_value(&self) -> f64 {
47        self.value
48    }
49
50    #[getter]
51    #[pyo3(name = "has_inputs")]
52    fn py_has_inputs(&self) -> bool {
53        self.has_inputs()
54    }
55
56    #[getter]
57    #[pyo3(name = "initialized")]
58    const fn py_initialized(&self) -> bool {
59        self.initialized
60    }
61
62    #[pyo3(name = "handle_book")]
63    fn py_handle_book(&mut self, book: &OrderBook) {
64        self.handle_book(book);
65    }
66
67    #[pyo3(name = "update")]
68    #[pyo3(signature = (best_bid=None, best_ask=None))]
69    fn py_update(&mut self, best_bid: Option<Quantity>, best_ask: Option<Quantity>) {
70        self.update(best_bid, best_ask);
71    }
72
73    #[pyo3(name = "reset")]
74    fn py_reset(&mut self) {
75        self.reset();
76    }
77}