Skip to main content

nautilus_databento/python/
data.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.
17
18use std::path::PathBuf;
19
20use nautilus_common::clients::DataClient;
21use nautilus_core::{python::to_pyruntime_err, time::get_atomic_clock_realtime};
22use nautilus_model::identifiers::ClientId;
23use pyo3::prelude::*;
24
25use crate::data::{DatabentoDataClient, DatabentoDataClientConfig};
26
27#[cfg(feature = "python")]
28#[pymethods]
29#[pyo3_stub_gen::derive::gen_stub_pymethods]
30impl DatabentoDataClient {
31    /// A Databento data client that combines live streaming and historical data functionality.
32    ///
33    /// This client uses the existing `DatabentoFeedHandler` for live data subscriptions
34    /// and `DatabentoHistoricalClient` for historical data requests. It supports multiple
35    /// datasets simultaneously, with separate feed handlers per dataset.
36    #[new]
37    #[pyo3(signature = (client_id, api_key, publishers_filepath, use_exchange_as_venue = true, bars_timestamp_on_close = true))]
38    pub fn py_new(
39        client_id: ClientId,
40        api_key: String,
41        publishers_filepath: PathBuf,
42        use_exchange_as_venue: bool,
43        bars_timestamp_on_close: bool,
44    ) -> PyResult<Self> {
45        let config = DatabentoDataClientConfig::new(
46            api_key,
47            publishers_filepath,
48            use_exchange_as_venue,
49            bars_timestamp_on_close,
50        );
51
52        Self::new(client_id, config, get_atomic_clock_realtime()).map_err(to_pyruntime_err)
53    }
54
55    /// Returns the client ID.
56    #[getter]
57    pub fn client_id(&self) -> ClientId {
58        DataClient::client_id(self)
59    }
60
61    /// Returns whether the client is connected.
62    #[getter]
63    pub fn is_connected(&self) -> bool {
64        DataClient::is_connected(self)
65    }
66
67    /// Returns whether the client is disconnected.
68    #[getter]
69    pub fn is_disconnected(&self) -> bool {
70        DataClient::is_disconnected(self)
71    }
72
73    /// Returns the API key associated with this client.
74    #[getter]
75    #[pyo3(name = "api_key")]
76    pub fn py_api_key(&self) -> &str {
77        self.api_key()
78    }
79
80    /// Returns a masked version of the API key for logging purposes.
81    #[getter]
82    #[pyo3(name = "api_key_masked")]
83    pub fn py_api_key_masked(&self) -> String {
84        self.api_key_masked()
85    }
86}