Skip to main content

nautilus_tardis/python/
enums.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
16use pyo3::prelude::*;
17use strum::IntoEnumIterator;
18
19use crate::common::enums::TardisExchange;
20
21#[must_use]
22#[pyfunction(name = "tardis_exchanges")]
23#[pyo3_stub_gen::derive::gen_stub_pyfunction(module = "nautilus_trader.tardis")]
24pub fn py_tardis_exchanges() -> Vec<String> {
25    TardisExchange::iter().map(|e| e.to_string()).collect()
26}
27
28#[must_use]
29#[pyfunction(name = "tardis_exchange_from_venue_str")]
30#[pyo3_stub_gen::derive::gen_stub_pyfunction(module = "nautilus_trader.tardis")]
31pub fn py_tardis_exchange_from_venue_str(venue_str: &str) -> Vec<String> {
32    TardisExchange::from_venue_str(venue_str)
33        .iter()
34        .map(ToString::to_string)
35        .collect()
36}
37
38#[must_use]
39#[pyfunction(name = "tardis_exchange_to_venue_str")]
40#[pyo3_stub_gen::derive::gen_stub_pyfunction(module = "nautilus_trader.tardis")]
41pub fn py_tardis_exchange_to_venue_str(exchange_str: &str) -> String {
42    match exchange_str.parse::<TardisExchange>() {
43        Ok(exchange) => exchange.as_venue_str().to_string(),
44        Err(_) => String::new(),
45    }
46}
47
48#[must_use]
49#[pyfunction(name = "tardis_exchange_is_option_exchange")]
50#[pyo3_stub_gen::derive::gen_stub_pyfunction(module = "nautilus_trader.tardis")]
51pub fn py_tardis_exchange_is_option_exchange(exchange_str: &str) -> bool {
52    match exchange_str.parse::<TardisExchange>() {
53        Ok(exchange) => exchange.is_option_exchange(),
54        Err(_) => false,
55    }
56}