Skip to main content

nautilus_model/python/defi/
size_estimator.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
16//! Python bindings for size estimation.
17
18use pyo3::prelude::*;
19
20use crate::defi::pool_analysis::size_estimator::SizeForImpactResult;
21
22#[pymethods]
23#[pyo3_stub_gen::derive::gen_stub_pymethods]
24impl SizeForImpactResult {
25    #[getter]
26    #[pyo3(name = "target_impact_bps")]
27    fn py_target_impact_bps(&self) -> u32 {
28        self.target_impact_bps
29    }
30
31    #[getter]
32    #[pyo3(name = "size")]
33    fn py_size(&self) -> String {
34        self.size.to_string()
35    }
36
37    #[getter]
38    #[pyo3(name = "actual_impact_bps")]
39    fn py_actual_impact_bps(&self) -> u32 {
40        self.actual_impact_bps
41    }
42
43    #[getter]
44    #[pyo3(name = "zero_for_one")]
45    fn py_zero_for_one(&self) -> bool {
46        self.zero_for_one
47    }
48
49    #[getter]
50    #[pyo3(name = "iterations")]
51    fn py_iterations(&self) -> u32 {
52        self.iterations
53    }
54
55    #[getter]
56    #[pyo3(name = "converged")]
57    fn py_converged(&self) -> bool {
58        self.converged
59    }
60
61    #[getter]
62    #[pyo3(name = "expansion_count")]
63    fn py_expansion_count(&self) -> u32 {
64        self.expansion_count
65    }
66
67    #[getter]
68    #[pyo3(name = "initial_high")]
69    fn py_initial_high(&self) -> String {
70        self.initial_high.to_string()
71    }
72
73    #[getter]
74    #[pyo3(name = "final_low")]
75    fn py_final_low(&self) -> String {
76        self.final_low.to_string()
77    }
78
79    #[getter]
80    #[pyo3(name = "final_high")]
81    fn py_final_high(&self) -> String {
82        self.final_high.to_string()
83    }
84
85    /// Check if the result is within the specified tolerance.
86    #[pyo3(name = "within_tolerance")]
87    fn py_within_tolerance(&self, tolerance_bps: u32) -> bool {
88        self.within_tolerance(tolerance_bps)
89    }
90
91    /// Get the convergence quality as a percentage.
92    ///
93    /// # Returns
94    /// Accuracy percentage (100.0 = perfect match, lower = less accurate)
95    #[pyo3(name = "accuracy_percent")]
96    fn py_accuracy_percent(&self) -> f64 {
97        self.accuracy_percent()
98    }
99
100    fn __str__(&self) -> String {
101        format!(
102            "SizeForImpactResult(target={}bps, actual={}bps, size={}, converged={}, iterations={})",
103            self.target_impact_bps,
104            self.actual_impact_bps,
105            self.size,
106            self.converged,
107            self.iterations,
108        )
109    }
110
111    fn __repr__(&self) -> String {
112        format!("{self:?}")
113    }
114}