nautilus_tardis/python/
csv.rs

1// -------------------------------------------------------------------------------------------------
2//  Copyright (C) 2015-2025 Posei Systems Pty Ltd. All rights reserved.
3//  https://poseitrader.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 std::path::PathBuf;
17
18use nautilus_core::python::to_pyvalue_err;
19use nautilus_model::{
20    data::{OrderBookDelta, OrderBookDepth10, QuoteTick, TradeTick},
21    identifiers::InstrumentId,
22};
23use pyo3::prelude::*;
24
25use crate::csv::{
26    load_deltas, load_depth10_from_snapshot5, load_depth10_from_snapshot25, load_quote_ticks,
27    load_trade_ticks,
28};
29
30/// # Errors
31///
32/// Returns a Python error if loading or parsing the CSV file fails.
33#[pyfunction(name = "load_tardis_deltas")]
34#[pyo3(signature = (filepath, price_precision=None, size_precision=None, instrument_id=None, limit=None))]
35pub fn py_load_tardis_deltas(
36    filepath: PathBuf,
37    price_precision: Option<u8>,
38    size_precision: Option<u8>,
39    instrument_id: Option<InstrumentId>,
40    limit: Option<usize>,
41) -> PyResult<Vec<OrderBookDelta>> {
42    load_deltas(
43        filepath,
44        price_precision,
45        size_precision,
46        instrument_id,
47        limit,
48    )
49    .map_err(to_pyvalue_err)
50}
51
52/// # Errors
53///
54/// Returns a Python error if loading or parsing the CSV file fails.
55#[pyfunction(name = "load_tardis_depth10_from_snapshot5")]
56#[pyo3(signature = (filepath, price_precision=None, size_precision=None, instrument_id=None, limit=None))]
57pub fn py_load_tardis_depth10_from_snapshot5(
58    filepath: PathBuf,
59    price_precision: Option<u8>,
60    size_precision: Option<u8>,
61    instrument_id: Option<InstrumentId>,
62    limit: Option<usize>,
63) -> PyResult<Vec<OrderBookDepth10>> {
64    load_depth10_from_snapshot5(
65        filepath,
66        price_precision,
67        size_precision,
68        instrument_id,
69        limit,
70    )
71    .map_err(to_pyvalue_err)
72}
73
74/// # Errors
75///
76/// Returns a Python error if loading or parsing the CSV file fails.
77#[pyfunction(name = "load_tardis_depth10_from_snapshot25")]
78#[pyo3(signature = (filepath, price_precision=None, size_precision=None, instrument_id=None, limit=None))]
79pub fn py_load_tardis_depth10_from_snapshot25(
80    filepath: PathBuf,
81    price_precision: Option<u8>,
82    size_precision: Option<u8>,
83    instrument_id: Option<InstrumentId>,
84    limit: Option<usize>,
85) -> PyResult<Vec<OrderBookDepth10>> {
86    load_depth10_from_snapshot25(
87        filepath,
88        price_precision,
89        size_precision,
90        instrument_id,
91        limit,
92    )
93    .map_err(to_pyvalue_err)
94}
95
96/// # Errors
97///
98/// Returns a Python error if loading or parsing the CSV file fails.
99#[pyfunction(name = "load_tardis_quotes")]
100#[pyo3(signature = (filepath, price_precision=None, size_precision=None, instrument_id=None, limit=None))]
101pub fn py_load_tardis_quotes(
102    filepath: PathBuf,
103    price_precision: Option<u8>,
104    size_precision: Option<u8>,
105    instrument_id: Option<InstrumentId>,
106    limit: Option<usize>,
107) -> PyResult<Vec<QuoteTick>> {
108    load_quote_ticks(
109        filepath,
110        price_precision,
111        size_precision,
112        instrument_id,
113        limit,
114    )
115    .map_err(to_pyvalue_err)
116}
117
118/// # Errors
119///
120/// Returns a Python error if loading or parsing the CSV file fails.
121#[pyfunction(name = "load_tardis_trades")]
122#[pyo3(signature = (filepath, price_precision=None, size_precision=None, instrument_id=None, limit=None))]
123pub fn py_load_tardis_trades(
124    filepath: PathBuf,
125    price_precision: Option<u8>,
126    size_precision: Option<u8>,
127    instrument_id: Option<InstrumentId>,
128    limit: Option<usize>,
129) -> PyResult<Vec<TradeTick>> {
130    load_trade_ticks(
131        filepath,
132        price_precision,
133        size_precision,
134        instrument_id,
135        limit,
136    )
137    .map_err(to_pyvalue_err)
138}