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