nautilus_tardis/python/
csv.rs

1// -------------------------------------------------------------------------------------------------
2//  Copyright (C) 2015-2025 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 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#[pyfunction(name = "load_tardis_deltas")]
31#[pyo3(signature = (filepath, price_precision=None, size_precision=None, instrument_id=None, limit=None))]
32pub fn py_load_tardis_deltas(
33    filepath: PathBuf,
34    price_precision: Option<u8>,
35    size_precision: Option<u8>,
36    instrument_id: Option<InstrumentId>,
37    limit: Option<usize>,
38) -> PyResult<Vec<OrderBookDelta>> {
39    load_deltas(
40        filepath,
41        price_precision,
42        size_precision,
43        instrument_id,
44        limit,
45    )
46    .map_err(to_pyvalue_err)
47}
48
49#[pyfunction(name = "load_tardis_depth10_from_snapshot5")]
50#[pyo3(signature = (filepath, price_precision=None, size_precision=None, instrument_id=None, limit=None))]
51pub fn py_load_tardis_depth10_from_snapshot5(
52    filepath: PathBuf,
53    price_precision: Option<u8>,
54    size_precision: Option<u8>,
55    instrument_id: Option<InstrumentId>,
56    limit: Option<usize>,
57) -> PyResult<Vec<OrderBookDepth10>> {
58    load_depth10_from_snapshot5(
59        filepath,
60        price_precision,
61        size_precision,
62        instrument_id,
63        limit,
64    )
65    .map_err(to_pyvalue_err)
66}
67
68#[pyfunction(name = "load_tardis_depth10_from_snapshot25")]
69#[pyo3(signature = (filepath, price_precision=None, size_precision=None, instrument_id=None, limit=None))]
70pub fn py_load_tardis_depth10_from_snapshot25(
71    filepath: PathBuf,
72    price_precision: Option<u8>,
73    size_precision: Option<u8>,
74    instrument_id: Option<InstrumentId>,
75    limit: Option<usize>,
76) -> PyResult<Vec<OrderBookDepth10>> {
77    load_depth10_from_snapshot25(
78        filepath,
79        price_precision,
80        size_precision,
81        instrument_id,
82        limit,
83    )
84    .map_err(to_pyvalue_err)
85}
86
87#[pyfunction(name = "load_tardis_quotes")]
88#[pyo3(signature = (filepath, price_precision=None, size_precision=None, instrument_id=None, limit=None))]
89pub fn py_load_tardis_quotes(
90    filepath: PathBuf,
91    price_precision: Option<u8>,
92    size_precision: Option<u8>,
93    instrument_id: Option<InstrumentId>,
94    limit: Option<usize>,
95) -> PyResult<Vec<QuoteTick>> {
96    load_quote_ticks(
97        filepath,
98        price_precision,
99        size_precision,
100        instrument_id,
101        limit,
102    )
103    .map_err(to_pyvalue_err)
104}
105
106#[pyfunction(name = "load_tardis_trades")]
107#[pyo3(signature = (filepath, price_precision=None, size_precision=None, instrument_id=None, limit=None))]
108pub fn py_load_tardis_trades(
109    filepath: PathBuf,
110    price_precision: Option<u8>,
111    size_precision: Option<u8>,
112    instrument_id: Option<InstrumentId>,
113    limit: Option<usize>,
114) -> PyResult<Vec<TradeTick>> {
115    load_trade_ticks(
116        filepath,
117        price_precision,
118        size_precision,
119        instrument_id,
120        limit,
121    )
122    .map_err(to_pyvalue_err)
123}