nautilus_persistence/python/
catalog.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_model::data::{Bar, OrderBookDelta, OrderBookDepth10, QuoteTick, TradeTick};
19use pyo3::prelude::*;
20
21use crate::backend::catalog::ParquetDataCatalog;
22
23/// A catalog for writing data to Parquet files.
24#[pyclass(name = "ParquetCatalogV2")]
25pub struct PyParquetDataCatalogV2 {
26    inner: ParquetDataCatalog,
27}
28
29#[pymethods]
30impl PyParquetDataCatalogV2 {
31    /// Create a new ParquetCatalog with the given base path and optional batch size.
32    #[new]
33    #[pyo3(signature = (base_path, batch_size=None))]
34    #[must_use]
35    pub fn new(base_path: String, batch_size: Option<usize>) -> Self {
36        Self {
37            inner: ParquetDataCatalog::new(PathBuf::from(base_path), batch_size),
38        }
39    }
40
41    // TODO: Cannot pass mixed data across pyo3 as a single type
42    // pub fn write_data(mut slf: PyRefMut<'_, Self>, data_type: NautilusDataType, data: Vec<Data>) {}
43
44    pub fn write_quote_ticks(&self, data: Vec<QuoteTick>) {
45        let _ = self.inner.write_to_parquet(data, None, None, None);
46    }
47
48    pub fn write_trade_ticks(&self, data: Vec<TradeTick>) {
49        let _ = self.inner.write_to_parquet(data, None, None, None);
50    }
51
52    pub fn write_order_book_deltas(&self, data: Vec<OrderBookDelta>) {
53        let _ = self.inner.write_to_parquet(data, None, None, None);
54    }
55
56    pub fn write_bars(&self, data: Vec<Bar>) {
57        let _ = self.inner.write_to_parquet(data, None, None, None);
58    }
59
60    pub fn write_order_book_depths(&self, data: Vec<OrderBookDepth10>) {
61        let _ = self.inner.write_to_parquet(data, None, None, None);
62    }
63}