Skip to main content

nautilus_execution/python/
fill.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 fill model types.
17
18use nautilus_core::python::to_pyruntime_err;
19use pyo3::prelude::*;
20
21use crate::models::fill::{
22    BestPriceFillModel, CompetitionAwareFillModel, DefaultFillModel, LimitOrderPartialFillModel,
23    MarketHoursFillModel, OneTickSlippageFillModel, ProbabilisticFillModel, SizeAwareFillModel,
24    ThreeTierFillModel, TwoTierFillModel, VolumeSensitiveFillModel,
25};
26
27macro_rules! impl_fill_model_pymethods {
28    ($type:ty) => {
29        #[pymethods]
30        #[pyo3_stub_gen::derive::gen_stub_pymethods]
31        impl $type {
32            #[new]
33            #[pyo3(signature = (prob_fill_on_limit=1.0, prob_slippage=0.0, random_seed=None))]
34            fn py_new(
35                prob_fill_on_limit: f64,
36                prob_slippage: f64,
37                random_seed: Option<u64>,
38            ) -> PyResult<Self> {
39                Self::new(prob_fill_on_limit, prob_slippage, random_seed).map_err(to_pyruntime_err)
40            }
41
42            fn __repr__(&self) -> String {
43                format!("{self:?}")
44            }
45        }
46    };
47}
48
49impl_fill_model_pymethods!(DefaultFillModel);
50impl_fill_model_pymethods!(BestPriceFillModel);
51impl_fill_model_pymethods!(OneTickSlippageFillModel);
52impl_fill_model_pymethods!(ProbabilisticFillModel);
53impl_fill_model_pymethods!(TwoTierFillModel);
54impl_fill_model_pymethods!(ThreeTierFillModel);
55impl_fill_model_pymethods!(LimitOrderPartialFillModel);
56impl_fill_model_pymethods!(SizeAwareFillModel);
57impl_fill_model_pymethods!(VolumeSensitiveFillModel);
58impl_fill_model_pymethods!(MarketHoursFillModel);
59
60#[pymethods]
61#[pyo3_stub_gen::derive::gen_stub_pymethods]
62impl CompetitionAwareFillModel {
63    /// Fill model that reduces available liquidity by a factor to simulate market competition.
64    #[new]
65    #[pyo3(signature = (
66        prob_fill_on_limit=1.0,
67        prob_slippage=0.0,
68        random_seed=None,
69        liquidity_factor=0.3,
70    ))]
71    fn py_new(
72        prob_fill_on_limit: f64,
73        prob_slippage: f64,
74        random_seed: Option<u64>,
75        liquidity_factor: f64,
76    ) -> PyResult<Self> {
77        Self::new(
78            prob_fill_on_limit,
79            prob_slippage,
80            random_seed,
81            liquidity_factor,
82        )
83        .map_err(to_pyruntime_err)
84    }
85
86    fn __repr__(&self) -> String {
87        format!("{self:?}")
88    }
89}