nautilus_model/python/orderbook/
level.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 pyo3::prelude::*;
17
18use crate::{
19    data::order::BookOrder,
20    orderbook::BookLevel,
21    types::{price::Price, quantity::QuantityRaw},
22};
23
24#[pymethods]
25impl BookLevel {
26    fn __repr__(&self) -> String {
27        format!("{self:?}")
28    }
29
30    fn __str__(&self) -> String {
31        // TODO: Return debug string for now
32        format!("{self:?}")
33    }
34
35    #[getter]
36    #[pyo3(name = "price")]
37    fn py_price(&self) -> Price {
38        self.price.value
39    }
40
41    #[pyo3(name = "len")]
42    fn py_len(&self) -> usize {
43        self.len()
44    }
45
46    #[pyo3(name = "is_empty")]
47    fn py_is_empty(&self) -> bool {
48        self.is_empty()
49    }
50
51    #[pyo3(name = "size")]
52    fn py_size(&self) -> f64 {
53        self.size()
54    }
55
56    #[pyo3(name = "size_raw")]
57    fn py_size_raw(&self) -> QuantityRaw {
58        self.size_raw()
59    }
60
61    #[pyo3(name = "exposure")]
62    fn py_exposure(&self) -> f64 {
63        self.exposure()
64    }
65
66    #[pyo3(name = "exposure_raw")]
67    fn py_exposure_raw(&self) -> QuantityRaw {
68        self.exposure_raw()
69    }
70
71    #[pyo3(name = "first")]
72    fn py_fist(&self) -> Option<BookOrder> {
73        self.first().copied()
74    }
75
76    #[pyo3(name = "get_orders")]
77    fn py_get_orders(&self) -> Vec<BookOrder> {
78        self.get_orders()
79    }
80}