Skip to main content

nautilus_binance/
config.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//! Binance adapter configuration structures.
17
18use std::any::Any;
19
20use nautilus_model::identifiers::{AccountId, TraderId};
21use nautilus_system::factories::ClientConfig;
22
23use crate::common::enums::{BinanceEnvironment, BinanceProductType};
24
25/// Configuration for Binance data client.
26///
27/// Ed25519 API keys are required for SBE WebSocket streams.
28#[derive(Clone, Debug)]
29pub struct BinanceDataClientConfig {
30    /// Product types to subscribe to.
31    pub product_types: Vec<BinanceProductType>,
32    /// Environment (mainnet or testnet).
33    pub environment: BinanceEnvironment,
34    /// Optional base URL override for HTTP API.
35    pub base_url_http: Option<String>,
36    /// Optional base URL override for WebSocket.
37    pub base_url_ws: Option<String>,
38    /// API key (Ed25519).
39    pub api_key: Option<String>,
40    /// API secret (Ed25519 base64-encoded or PEM).
41    pub api_secret: Option<String>,
42}
43
44impl Default for BinanceDataClientConfig {
45    fn default() -> Self {
46        Self {
47            product_types: vec![BinanceProductType::Spot],
48            environment: BinanceEnvironment::Mainnet,
49            base_url_http: None,
50            base_url_ws: None,
51            api_key: None,
52            api_secret: None,
53        }
54    }
55}
56
57impl ClientConfig for BinanceDataClientConfig {
58    fn as_any(&self) -> &dyn Any {
59        self
60    }
61}
62
63/// Configuration for Binance execution client.
64///
65/// Ed25519 API keys are required for execution clients. Binance deprecated
66/// listenKey-based user data streams in favor of WebSocket API authentication,
67/// which only supports Ed25519.
68#[derive(Clone, Debug)]
69pub struct BinanceExecClientConfig {
70    /// Trader ID for the client.
71    pub trader_id: TraderId,
72    /// Account ID for the client.
73    pub account_id: AccountId,
74    /// Product types to trade.
75    pub product_types: Vec<BinanceProductType>,
76    /// Environment (mainnet or testnet).
77    pub environment: BinanceEnvironment,
78    /// Optional base URL override for HTTP API.
79    pub base_url_http: Option<String>,
80    /// Optional base URL override for WebSocket.
81    pub base_url_ws: Option<String>,
82    /// API key (Ed25519 required, uses env var if not provided).
83    pub api_key: Option<String>,
84    /// API secret (Ed25519 base64-encoded, required, uses env var if not provided).
85    pub api_secret: Option<String>,
86}
87
88impl ClientConfig for BinanceExecClientConfig {
89    fn as_any(&self) -> &dyn Any {
90        self
91    }
92}