nautilus_execution/python/latency.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 latency model types.
17
18use nautilus_core::UnixNanos;
19use pyo3::prelude::*;
20
21use crate::models::latency::StaticLatencyModel;
22
23#[pymethods]
24#[pyo3_stub_gen::derive::gen_stub_pymethods]
25impl StaticLatencyModel {
26 /// Static latency model with fixed latency values.
27 ///
28 /// Models the latency for different order operations including base network latency
29 /// and specific operation latencies for insert, update, and delete operations.
30 ///
31 /// The base latency is automatically added to each operation latency, matching
32 /// Python's behavior. For example, if `base_latency_nanos = 100ms` and
33 /// `insert_latency_nanos = 200ms`, the effective insert latency will be 300ms.
34 #[new]
35 #[pyo3(signature = (
36 base_latency_nanos = 0,
37 insert_latency_nanos = 0,
38 update_latency_nanos = 0,
39 cancel_latency_nanos = 0,
40 ))]
41 fn py_new(
42 base_latency_nanos: u64,
43 insert_latency_nanos: u64,
44 update_latency_nanos: u64,
45 cancel_latency_nanos: u64,
46 ) -> Self {
47 Self::new(
48 UnixNanos::from(base_latency_nanos),
49 UnixNanos::from(insert_latency_nanos),
50 UnixNanos::from(update_latency_nanos),
51 UnixNanos::from(cancel_latency_nanos),
52 )
53 }
54
55 fn __repr__(&self) -> String {
56 format!("{self:?}")
57 }
58}