Skip to main content

nautilus_databento/python/
factories.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 the Databento data client factory.
17
18use std::path::PathBuf;
19
20use nautilus_core::{python::to_pyruntime_err, time::get_atomic_clock_realtime};
21use nautilus_model::identifiers::ClientId;
22use pyo3::prelude::*;
23
24use crate::{
25    data::DatabentoDataClient,
26    factories::{DatabentoDataClientFactory, DatabentoLiveClientConfig},
27};
28
29#[pymethods]
30#[pyo3_stub_gen::derive::gen_stub_pymethods]
31impl DatabentoLiveClientConfig {
32    /// Configuration for Databento data clients used with `LiveNode`.
33    #[new]
34    #[pyo3(signature = (api_key, publishers_filepath, use_exchange_as_venue=false, bars_timestamp_on_close=true))]
35    fn py_new(
36        api_key: String,
37        publishers_filepath: std::path::PathBuf,
38        use_exchange_as_venue: bool,
39        bars_timestamp_on_close: bool,
40    ) -> Self {
41        Self::new(
42            api_key,
43            publishers_filepath,
44            use_exchange_as_venue,
45            bars_timestamp_on_close,
46        )
47    }
48
49    fn __repr__(&self) -> String {
50        format!("{self:?}")
51    }
52}
53
54#[pymethods]
55#[pyo3_stub_gen::derive::gen_stub_pymethods]
56impl DatabentoDataClientFactory {
57    /// Factory for creating Databento data clients.
58    #[new]
59    fn py_new() -> Self {
60        Self
61    }
62
63    #[pyo3(name = "name")]
64    fn py_name(&self) -> &'static str {
65        "DATABENTO"
66    }
67
68    /// Creates a new `DatabentoDataClient` instance.
69    #[staticmethod]
70    #[pyo3(signature = (client_id, api_key, publishers_filepath, use_exchange_as_venue = true, bars_timestamp_on_close = true))]
71    pub fn py_create_live_data_client(
72        client_id: ClientId,
73        api_key: String,
74        publishers_filepath: PathBuf,
75        use_exchange_as_venue: bool,
76        bars_timestamp_on_close: bool,
77    ) -> PyResult<DatabentoDataClient> {
78        Self::create_live_data_client(
79            client_id,
80            api_key,
81            publishers_filepath,
82            use_exchange_as_venue,
83            bars_timestamp_on_close,
84            get_atomic_clock_realtime(),
85        )
86        .map_err(to_pyruntime_err)
87    }
88}