1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
//! Binance fee management example.
//!
//! Note: Many fee-related methods (fetch_funding_rate, fetch_funding_rate_history,
//! fetch_funding_rates, fetch_leverage_tiers) are not yet migrated to the new
//! modular structure. This example demonstrates the available methods.
//!
//! # Environment Variables
//!
//! - `BINANCE_API_KEY`: API key for authenticated endpoints (optional)
//! - `BINANCE_API_SECRET`: API secret for authenticated endpoints (optional)
//!
//! # Examples
//!
//! ```bash
//! # Run with authentication
//! BINANCE_API_KEY=your_key BINANCE_API_SECRET=your_secret cargo run --example binance_fee_example
//! ```
use ccxt_core::ExchangeConfig;
use ccxt_exchanges::prelude::Binance;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
tracing_subscriber::fmt::init();
let config = ExchangeConfig {
api_key: std::env::var("BINANCE_API_KEY")
.ok()
.map(ccxt_core::SecretString::new),
secret: std::env::var("BINANCE_API_SECRET")
.ok()
.map(ccxt_core::SecretString::new),
sandbox: false,
..Default::default()
};
let binance = Binance::new(config)?;
println!("=== Binance Fee Management Examples ===\n");
// Example 1: Fetch trading fee for a single symbol (requires API key)
// Returns typed FeeTradingFee struct
if binance.base().config.api_key.is_some() {
println!("1. Fetching BTC/USDT trading fee...");
match binance.fetch_trading_fee("BTC/USDT", None).await {
Ok(fee) => {
println!(" Symbol: {}", fee.symbol);
println!(" Maker fee: {}", fee.maker);
println!(" Taker fee: {}", fee.taker);
println!(" ✅ Success\n");
}
Err(e) => println!(" ❌ Error: {}\n", e),
}
println!("2. Fetching trading fees for all symbols...");
match binance.fetch_trading_fees(None, None).await {
Ok(fees) => {
println!(" Total symbols: {}", fees.len());
for (symbol, fee) in fees.iter().take(5) {
println!(" {}: maker={}, taker={}", symbol, fee.maker, fee.taker);
}
println!(" ✅ Success\n");
}
Err(e) => println!(" ❌ Error: {}\n", e),
}
} else {
println!("⚠️ No API credentials set, skipping authenticated endpoints");
println!(" Set environment variables: BINANCE_API_KEY and BINANCE_API_SECRET\n");
}
// Note: The following methods are not yet migrated to the new modular structure:
// - fetch_funding_rate
// - fetch_funding_rate_history
// - fetch_funding_rates
// - fetch_leverage_tiers
println!("Note: Funding rate and leverage tier methods are not yet migrated.");
println!(" See rest_old.rs for the original implementations.\n");
println!("=== Examples Complete ===");
Ok(())
}