nautilus_coinbase_intx/python/
fix.rs

1// -------------------------------------------------------------------------------------------------
2//  Copyright (C) 2015-2025 Posei Systems Pty Ltd. All rights reserved.
3//  https://poseitrader.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//! Provides `PyO3` bindings for the Coinbase International FIX client.
17
18use nautilus_core::python::{to_pyruntime_err, to_pyvalue_err};
19use pyo3::prelude::*;
20
21use crate::fix::client::CoinbaseIntxFixClient;
22
23#[pymethods]
24impl CoinbaseIntxFixClient {
25    #[new]
26    #[pyo3(signature = (endpoint=None, api_key=None, api_secret=None, api_passphrase=None, portfolio_id=None))]
27    fn py_new(
28        endpoint: Option<String>,
29        api_key: Option<String>,
30        api_secret: Option<String>,
31        api_passphrase: Option<String>,
32        portfolio_id: Option<String>,
33    ) -> PyResult<Self> {
34        Self::new(endpoint, api_key, api_secret, api_passphrase, portfolio_id)
35            .map_err(to_pyvalue_err)
36    }
37
38    #[getter]
39    #[pyo3(name = "endpoint")]
40    #[must_use]
41    pub const fn py_endpoint(&self) -> &str {
42        self.endpoint()
43    }
44
45    #[getter]
46    #[pyo3(name = "api_key")]
47    #[must_use]
48    pub const fn py_api_key(&self) -> &str {
49        self.api_key()
50    }
51
52    #[getter]
53    #[pyo3(name = "portfolio_id")]
54    #[must_use]
55    pub const fn py_portfolio_id(&self) -> &str {
56        self.portfolio_id()
57    }
58
59    #[getter]
60    #[pyo3(name = "sender_comp_id")]
61    #[must_use]
62    pub const fn py_sender_comp_id(&self) -> &str {
63        self.sender_comp_id()
64    }
65
66    #[getter]
67    #[pyo3(name = "target_comp_id")]
68    #[must_use]
69    pub const fn py_target_comp_id(&self) -> &str {
70        self.target_comp_id()
71    }
72
73    #[pyo3(name = "is_connected")]
74    fn py_is_connected(&self) -> bool {
75        self.is_connected()
76    }
77
78    #[pyo3(name = "is_logged_on")]
79    fn py_is_logged_on(&self) -> bool {
80        self.is_logged_on()
81    }
82
83    #[pyo3(name = "connect")]
84    fn py_connect<'py>(
85        &mut self,
86        py: Python<'py>,
87        handler: PyObject,
88    ) -> PyResult<Bound<'py, PyAny>> {
89        let mut client = self.clone();
90
91        pyo3_async_runtimes::tokio::future_into_py(py, async move {
92            client.connect(handler).await.map_err(to_pyruntime_err)
93        })
94    }
95
96    #[pyo3(name = "close")]
97    fn py_close<'py>(&mut self, py: Python<'py>) -> PyResult<Bound<'py, PyAny>> {
98        let mut client = self.clone();
99
100        pyo3_async_runtimes::tokio::future_into_py(py, async move {
101            client.close().await.map_err(to_pyruntime_err)
102        })
103    }
104}