nautilus_model/python/defi/
profiler.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
16//! Python bindings for DeFi pool profiler.
17
18use pyo3::prelude::*;
19
20use crate::{
21    defi::{Pool, pool_analysis::PoolProfiler},
22    identifiers::InstrumentId,
23};
24
25#[pymethods]
26impl PoolProfiler {
27    #[getter]
28    #[pyo3(name = "pool")]
29    fn py_pool(&self) -> Pool {
30        self.pool.as_ref().clone()
31    }
32
33    #[getter]
34    #[pyo3(name = "instrument_id")]
35    fn py_instrument_id(&self) -> InstrumentId {
36        self.pool.instrument_id
37    }
38
39    #[getter]
40    #[pyo3(name = "is_initialized")]
41    fn py_is_initialized(&self) -> bool {
42        self.is_initialized
43    }
44
45    #[getter]
46    #[pyo3(name = "current_tick")]
47    fn py_current_tick(&self) -> i32 {
48        self.state.current_tick
49    }
50
51    #[getter]
52    #[pyo3(name = "price_sqrt_ratio_x96")]
53    fn py_price_sqrt_ratio_x96(&self) -> String {
54        self.state.price_sqrt_ratio_x96.to_string()
55    }
56
57    #[getter]
58    #[pyo3(name = "total_amount0_deposited")]
59    fn py_total_amount0_deposited(&self) -> String {
60        self.analytics.total_amount0_deposited.to_string()
61    }
62
63    #[getter]
64    #[pyo3(name = "total_amount1_deposited")]
65    fn py_total_amount1_deposited(&self) -> String {
66        self.analytics.total_amount1_deposited.to_string()
67    }
68
69    #[getter]
70    #[pyo3(name = "total_amount0_collected")]
71    fn py_total_amount0_collected(&self) -> String {
72        self.analytics.total_amount0_collected.to_string()
73    }
74
75    #[getter]
76    #[pyo3(name = "total_amount1_collected")]
77    fn py_total_amount1_collected(&self) -> String {
78        self.analytics.total_amount1_collected.to_string()
79    }
80
81    #[getter]
82    #[pyo3(name = "protocol_fees_token0")]
83    fn py_protocol_fees_token0(&self) -> String {
84        self.state.protocol_fees_token0.to_string()
85    }
86
87    #[getter]
88    #[pyo3(name = "protocol_fees_token1")]
89    fn py_protocol_fees_token1(&self) -> String {
90        self.state.protocol_fees_token1.to_string()
91    }
92
93    #[getter]
94    #[pyo3(name = "fee_protocol")]
95    fn py_fee_protocol(&self) -> u8 {
96        self.state.fee_protocol
97    }
98
99    #[pyo3(name = "get_active_liquidity")]
100    fn py_get_active_liquidity(&self) -> u128 {
101        self.get_active_liquidity()
102    }
103
104    #[pyo3(name = "get_active_tick_count")]
105    fn py_get_active_tick_count(&self) -> usize {
106        self.get_active_tick_count()
107    }
108
109    #[pyo3(name = "get_total_tick_count")]
110    fn py_get_total_tick_count(&self) -> usize {
111        self.get_total_tick_count()
112    }
113
114    #[pyo3(name = "get_total_active_positions")]
115    fn py_get_total_active_positions(&self) -> usize {
116        self.get_total_active_positions()
117    }
118
119    #[pyo3(name = "get_total_inactive_positions")]
120    fn py_get_total_inactive_positions(&self) -> usize {
121        self.get_total_inactive_positions()
122    }
123
124    #[pyo3(name = "estimate_balance_of_token0")]
125    fn py_estimate_balance_of_token0(&self) -> String {
126        self.estimate_balance_of_token0().to_string()
127    }
128
129    #[pyo3(name = "estimate_balance_of_token1")]
130    fn py_estimate_balance_of_token1(&self) -> String {
131        self.estimate_balance_of_token1().to_string()
132    }
133}