pub struct BinanceBuilder { /* private fields */ }Expand description
Builder for creating Binance exchange instances.
Provides a fluent API for configuring all aspects of the Binance exchange, including authentication, connection settings, and Binance-specific options.
§Example
use ccxt_exchanges::binance::BinanceBuilder;
let binance = BinanceBuilder::new()
.api_key("your-api-key")
.secret("your-secret")
.sandbox(true)
.timeout(30)
.build()
.unwrap();Implementations§
Source§impl BinanceBuilder
impl BinanceBuilder
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates a new builder with default configuration.
§Example
use ccxt_exchanges::binance::BinanceBuilder;
let builder = BinanceBuilder::new();Sourcepub fn sandbox(self, enabled: bool) -> Self
pub fn sandbox(self, enabled: bool) -> Self
Enables or disables sandbox/testnet mode.
When enabled, the exchange will connect to Binance’s testnet instead of the production environment.
§Arguments
enabled- Whether to enable sandbox mode.
§Example
use ccxt_exchanges::binance::BinanceBuilder;
let builder = BinanceBuilder::new()
.sandbox(true);Sourcepub fn timeout_secs(self, seconds: u64) -> Self
pub fn timeout_secs(self, seconds: u64) -> Self
Sets the request timeout in seconds (convenience method).
§Arguments
seconds- Timeout duration in seconds.
Sourcepub fn connect_timeout(self, timeout: Duration) -> Self
pub fn connect_timeout(self, timeout: Duration) -> Self
Sourcepub fn connect_timeout_secs(self, seconds: u64) -> Self
pub fn connect_timeout_secs(self, seconds: u64) -> Self
Sets the TCP connection timeout in seconds (convenience method).
§Arguments
seconds- Connection timeout duration in seconds.
Sourcepub fn retry_policy(self, policy: RetryPolicy) -> Self
pub fn retry_policy(self, policy: RetryPolicy) -> Self
Sets the retry policy.
Sourcepub fn recv_window(self, millis: u64) -> Self
pub fn recv_window(self, millis: u64) -> Self
Sets the receive window for signed requests.
The receive window specifies how long a request is valid after the timestamp. Default is 5000 milliseconds.
§Arguments
millis- Receive window in milliseconds.
§Example
use ccxt_exchanges::binance::BinanceBuilder;
let builder = BinanceBuilder::new()
.recv_window(10000);Sourcepub fn default_type(self, trading_type: impl Into<DefaultType>) -> Self
pub fn default_type(self, trading_type: impl Into<DefaultType>) -> Self
Sets the default trading type.
Accepts both DefaultType enum values and string values for backward compatibility.
Valid string values: “spot”, “margin”, “swap”, “futures”, “option”.
Legacy values “future” and “delivery” are also supported.
§Arguments
trading_type- The default trading type (DefaultType or string).
§Example
use ccxt_exchanges::binance::BinanceBuilder;
use ccxt_core::types::default_type::DefaultType;
// Using DefaultType enum (recommended)
let builder = BinanceBuilder::new()
.default_type(DefaultType::Swap);
// Using string (backward compatible)
let builder = BinanceBuilder::new()
.default_type("swap");Sourcepub fn default_sub_type(self, sub_type: DefaultSubType) -> Self
pub fn default_sub_type(self, sub_type: DefaultSubType) -> Self
Sets the default sub-type for contract settlement.
Linear: USDT-margined contracts (FAPI)Inverse: Coin-margined contracts (DAPI)
Only applicable when default_type is Swap, Futures, or Option.
§Arguments
sub_type- The default sub-type for contract settlement.
§Example
use ccxt_exchanges::binance::BinanceBuilder;
use ccxt_core::types::default_type::{DefaultType, DefaultSubType};
let builder = BinanceBuilder::new()
.default_type(DefaultType::Swap)
.default_sub_type(DefaultSubType::Linear);Sourcepub fn adjust_for_time_difference(self, enabled: bool) -> Self
pub fn adjust_for_time_difference(self, enabled: bool) -> Self
Enables or disables time synchronization adjustment.
When enabled, the exchange will adjust for time differences between the local system and Binance servers.
§Arguments
enabled- Whether to enable time adjustment.
§Example
use ccxt_exchanges::binance::BinanceBuilder;
let builder = BinanceBuilder::new()
.adjust_for_time_difference(true);Sourcepub fn time_sync_interval(self, seconds: u64) -> Self
pub fn time_sync_interval(self, seconds: u64) -> Self
Sets the time sync interval in seconds.
Controls how often the time offset is refreshed when auto sync is enabled. Default is 30 seconds.
§Arguments
seconds- Sync interval in seconds.
§Example
use ccxt_exchanges::binance::BinanceBuilder;
let builder = BinanceBuilder::new()
.time_sync_interval(60); // Sync every 60 secondsSourcepub fn auto_time_sync(self, enabled: bool) -> Self
pub fn auto_time_sync(self, enabled: bool) -> Self
Enables or disables automatic periodic time sync.
When enabled, the time offset will be automatically refreshed based on the configured sync interval. Default is true.
§Arguments
enabled- Whether to enable automatic time sync.
§Example
use ccxt_exchanges::binance::BinanceBuilder;
// Disable automatic sync for manual control
let builder = BinanceBuilder::new()
.auto_time_sync(false);Sourcepub fn enable_rate_limit(self, enabled: bool) -> Self
pub fn enable_rate_limit(self, enabled: bool) -> Self
Sourcepub fn proxy(self, proxy: ProxyConfig) -> Self
pub fn proxy(self, proxy: ProxyConfig) -> Self
Sourcepub fn options(self, options: HashMap<String, Value>) -> Self
pub fn options(self, options: HashMap<String, Value>) -> Self
Sets multiple custom options.
§Arguments
options- HashMap of option key-value pairs.
§Example
use ccxt_exchanges::binance::BinanceBuilder;
use serde_json::json;
use std::collections::HashMap;
let mut options = HashMap::new();
options.insert("option1".to_string(), json!("value1"));
options.insert("option2".to_string(), json!(42));
let builder = BinanceBuilder::new()
.options(options);Sourcepub fn build(self) -> Result<Binance>
pub fn build(self) -> Result<Binance>
Builds the Binance exchange instance.
§Returns
Returns a Result containing the configured Binance instance.
§Errors
Returns an error if the exchange cannot be initialized.
§Example
use ccxt_exchanges::binance::BinanceBuilder;
let binance = BinanceBuilder::new()
.api_key("your-api-key")
.secret("your-secret")
.build()
.unwrap();Trait Implementations§
Source§impl Clone for BinanceBuilder
impl Clone for BinanceBuilder
Source§fn clone(&self) -> BinanceBuilder
fn clone(&self) -> BinanceBuilder
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more