nautilus_kraken/python/mod.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
16//! Python bindings from `pyo3`.
17
18use pyo3::prelude::*;
19
20use crate::{
21 common::enums::{KrakenEnvironment, KrakenProductType},
22 http::{KrakenFuturesHttpClient, KrakenSpotHttpClient},
23 websocket::{
24 futures::client::KrakenFuturesWebSocketClient, spot_v2::client::KrakenSpotWebSocketClient,
25 },
26};
27
28pub mod enums;
29pub mod http_futures;
30pub mod http_spot;
31pub mod websocket_futures;
32pub mod websocket_spot;
33
34/// Determines the product type from a Kraken symbol.
35///
36/// Futures symbols have the following prefixes:
37/// - `PI_` - Perpetual Inverse futures (e.g., `PI_XBTUSD`)
38/// - `PF_` - Perpetual Fixed-margin futures (e.g., `PF_XBTUSD`)
39/// - `FI_` - Fixed maturity Inverse futures (e.g., `FI_XBTUSD_230929`)
40/// - `FF_` - Flex futures
41///
42/// All other symbols are considered spot.
43#[pyfunction]
44#[pyo3(name = "kraken_product_type_from_symbol")]
45fn py_kraken_product_type_from_symbol(symbol: &str) -> KrakenProductType {
46 crate::common::enums::product_type_from_symbol(symbol)
47}
48
49#[pymodule]
50pub fn kraken(m: &Bound<'_, PyModule>) -> PyResult<()> {
51 m.add_class::<KrakenEnvironment>()?;
52 m.add_class::<KrakenProductType>()?;
53 m.add_class::<KrakenSpotHttpClient>()?;
54 m.add_class::<KrakenFuturesHttpClient>()?;
55 m.add_class::<KrakenSpotWebSocketClient>()?;
56 m.add_class::<KrakenFuturesWebSocketClient>()?;
57
58 m.add_function(wrap_pyfunction!(py_kraken_product_type_from_symbol, m)?)?;
59
60 Ok(())
61}