nautilus_model/python/defi/
quote.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::defi::pool_analysis::quote::SwapQuote;
19
20#[pymethods]
21impl SwapQuote {
22    #[getter]
23    #[pyo3(name = "amount0")]
24    fn py_amount0(&self) -> String {
25        self.amount0.to_string()
26    }
27
28    #[getter]
29    #[pyo3(name = "amount1")]
30    fn py_amount1(&self) -> String {
31        self.amount1.to_string()
32    }
33
34    #[getter]
35    #[pyo3(name = "sqrt_price_before_x96")]
36    fn py_sqrt_price_before_x96(&self) -> String {
37        self.sqrt_price_before_x96.to_string()
38    }
39
40    #[getter]
41    #[pyo3(name = "sqrt_price_after_x96")]
42    fn py_sqrt_price_after_x96(&self) -> String {
43        self.sqrt_price_after_x96.to_string()
44    }
45
46    #[getter]
47    #[pyo3(name = "tick_before")]
48    fn py_tick_before(&self) -> i32 {
49        self.tick_before
50    }
51
52    #[getter]
53    #[pyo3(name = "tick_after")]
54    fn py_tick_after(&self) -> i32 {
55        self.tick_after
56    }
57
58    #[getter]
59    #[pyo3(name = "liquidity_after")]
60    fn py_liquidity_after(&self) -> u128 {
61        self.liquidity_after
62    }
63
64    #[getter]
65    #[pyo3(name = "fee_growth_global_after")]
66    fn py_fee_growth_global_after(&self) -> String {
67        self.fee_growth_global_after.to_string()
68    }
69
70    #[getter]
71    #[pyo3(name = "lp_fee")]
72    fn py_lp_fee(&self) -> String {
73        self.lp_fee.to_string()
74    }
75
76    #[getter]
77    #[pyo3(name = "protocol_fee")]
78    fn py_protocol_fee(&self) -> String {
79        self.protocol_fee.to_string()
80    }
81
82    #[getter]
83    #[pyo3(name = "crossed_ticks_count")]
84    fn py_crossed_ticks_count(&self) -> usize {
85        self.crossed_ticks.len()
86    }
87
88    #[pyo3(name = "zero_for_one")]
89    fn py_zero_for_one(&self) -> bool {
90        self.zero_for_one()
91    }
92
93    #[pyo3(name = "total_fee")]
94    fn py_total_fee(&self) -> String {
95        self.total_fee().to_string()
96    }
97
98    #[pyo3(name = "total_crossed_ticks")]
99    fn py_total_crossed_ticks(&self) -> u32 {
100        self.total_crossed_ticks()
101    }
102
103    #[pyo3(name = "get_output_amount")]
104    fn py_get_output_amount(&self) -> String {
105        self.get_output_amount().to_string()
106    }
107
108    fn __str__(&self) -> String {
109        format!(
110            "SwapQuote(amount0={}, amount1={}, tick_before={}, tick_after={}, liquidity_after={}, total_fee={})",
111            self.amount0,
112            self.amount1,
113            self.tick_before,
114            self.tick_after,
115            self.liquidity_after,
116            self.total_fee()
117        )
118    }
119
120    fn __repr__(&self) -> String {
121        format!("{self:?}")
122    }
123}