Skip to main content

nautilus_execution/python/
fee.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 fee model types.
17
18use nautilus_core::python::to_pyruntime_err;
19use nautilus_model::types::Money;
20use pyo3::prelude::*;
21use rust_decimal::Decimal;
22
23use crate::models::fee::{
24    CappedOptionFeeModel, FixedFeeModel, MakerTakerFeeModel, PerContractFeeModel,
25    TieredNotionalOptionFeeModel,
26};
27
28#[pymethods]
29#[pyo3_stub_gen::derive::gen_stub_pymethods]
30impl FixedFeeModel {
31    /// Creates a new `FixedFeeModel` instance.
32    ///
33    /// # Errors
34    ///
35    /// Returns an error if `commission` is negative.
36    #[new]
37    #[pyo3(signature = (commission, change_commission_once=None))]
38    fn py_new(commission: Money, change_commission_once: Option<bool>) -> PyResult<Self> {
39        Self::new(commission, change_commission_once).map_err(to_pyruntime_err)
40    }
41
42    fn __repr__(&self) -> String {
43        format!("{self:?}")
44    }
45}
46
47#[pymethods]
48#[pyo3_stub_gen::derive::gen_stub_pymethods]
49impl MakerTakerFeeModel {
50    #[new]
51    fn py_new() -> Self {
52        Self
53    }
54
55    fn __repr__(&self) -> String {
56        format!("{self:?}")
57    }
58}
59
60#[pymethods]
61#[pyo3_stub_gen::derive::gen_stub_pymethods]
62impl PerContractFeeModel {
63    /// Creates a new `PerContractFeeModel` instance.
64    ///
65    /// # Errors
66    ///
67    /// Returns an error if `commission` is negative.
68    #[new]
69    fn py_new(commission: Money) -> PyResult<Self> {
70        Self::new(commission).map_err(to_pyruntime_err)
71    }
72
73    fn __repr__(&self) -> String {
74        format!("{self:?}")
75    }
76}
77
78#[pymethods]
79#[pyo3_stub_gen::derive::gen_stub_pymethods]
80impl CappedOptionFeeModel {
81    /// Creates a new `CappedOptionFeeModel` instance.
82    #[new]
83    #[pyo3(signature = (maker_rate=None, taker_rate=None, cap_rate=None))]
84    fn py_new(
85        maker_rate: Option<Decimal>,
86        taker_rate: Option<Decimal>,
87        cap_rate: Option<Decimal>,
88    ) -> PyResult<Self> {
89        Self::new(maker_rate, taker_rate, cap_rate).map_err(to_pyruntime_err)
90    }
91
92    fn __repr__(&self) -> String {
93        format!("{self:?}")
94    }
95}
96
97#[pymethods]
98#[pyo3_stub_gen::derive::gen_stub_pymethods]
99impl TieredNotionalOptionFeeModel {
100    /// Creates a new `TieredNotionalOptionFeeModel` instance.
101    ///
102    /// # Errors
103    ///
104    /// Returns an error if any supplied rate is negative.
105    #[new]
106    #[pyo3(signature = (maker_rate=None, taker_rate=None))]
107    fn py_new(maker_rate: Option<Decimal>, taker_rate: Option<Decimal>) -> PyResult<Self> {
108        Self::new(maker_rate, taker_rate).map_err(to_pyruntime_err)
109    }
110
111    fn __repr__(&self) -> String {
112        format!("{self:?}")
113    }
114}