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::*;
21
22use crate::models::fee::{FixedFeeModel, MakerTakerFeeModel, PerContractFeeModel};
23
24#[pymethods]
25#[pyo3_stub_gen::derive::gen_stub_pymethods]
26impl FixedFeeModel {
27    /// Creates a new `FixedFeeModel` instance.
28    ///
29    /// # Errors
30    ///
31    /// Returns an error if `commission` is negative.
32    #[new]
33    #[pyo3(signature = (commission, change_commission_once=None))]
34    fn py_new(commission: Money, change_commission_once: Option<bool>) -> PyResult<Self> {
35        Self::new(commission, change_commission_once).map_err(to_pyruntime_err)
36    }
37
38    fn __repr__(&self) -> String {
39        format!("{self:?}")
40    }
41}
42
43#[pymethods]
44#[pyo3_stub_gen::derive::gen_stub_pymethods]
45impl MakerTakerFeeModel {
46    #[new]
47    fn py_new() -> Self {
48        Self
49    }
50
51    fn __repr__(&self) -> String {
52        format!("{self:?}")
53    }
54}
55
56#[pymethods]
57#[pyo3_stub_gen::derive::gen_stub_pymethods]
58impl PerContractFeeModel {
59    /// Creates a new `PerContractFeeModel` instance.
60    ///
61    /// # Errors
62    ///
63    /// Returns an error if `commission` is negative.
64    #[new]
65    fn py_new(commission: Money) -> PyResult<Self> {
66        Self::new(commission).map_err(to_pyruntime_err)
67    }
68
69    fn __repr__(&self) -> String {
70        format!("{self:?}")
71    }
72}