Skip to content

Commit de41679

Browse files
author
github-actions
committed
Release v33.0.0
### Changed (1) - The crate no longer auto-initializes a global `tracing` subscriber. Logging configuration is now opt-in and must be performed by the application. The existing helper `logger::init()` is still available, but it is no longer called automatically by the library. - If you previously relied on the connector to set up logging for you, call this once in your application before creating any clients: ```rust use binance_sdk::logger; fn main() { logger::init(); } ``` - If your application already configures a global `tracing` subscriber, nothing changes: `logger::init()` is not called by the library and if you call it yourself it will early-return when a subscriber is already set. **Derivatives Trading Usds Futures** ### Added (2) #### REST API - `rpi_order_book()` (`GET /fapi/v1/rpiDepth`) #### WebSocket Streams - `rpi_diff_book_depth_streams()` (`<symbol>@rpiDepth@500ms` stream) ### Changed (2) #### REST API - Modified response for `user_commission_rate()` (`GET /dapi/v1/commissionRate`): - property `rpi_commission_rate` added #### WebSocket Streams - Modified `UserDataStreamEventsResponse` for `AlgoUpdate`: - `o`: property `rm` added **Simple Earn** ### Changed (2) - Modified response for `get_bfusd_account()` (`GET /sapi/v1/bfusd/account`): - property `usdt_profit` added - property `bfusd_profit` added - property `total_profit` removed - Modified response for `get_bfusd_rewards_history()` (`GET /sapi/v1/bfusd/history/rewardsHistory`): - `rows`.items: property `reward_asset` added
1 parent a093b79 commit de41679

File tree

71 files changed

+1293
-204
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+1293
-204
lines changed

CHANGELOG.md

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,59 @@
11
# Changelog
22

3+
## 33.0.0 - 2025-11-27
4+
5+
### Changed (1)
6+
7+
- The crate no longer auto-initializes a global `tracing` subscriber. Logging configuration is now opt-in and must be performed by the application. The existing helper `logger::init()` is still available, but it is no longer called automatically by the library.
8+
9+
- If you previously relied on the connector to set up logging for you, call this once in your application before creating any clients:
10+
11+
```rust
12+
use binance_sdk::logger;
13+
14+
fn main() {
15+
logger::init();
16+
}
17+
```
18+
19+
- If your application already configures a global `tracing` subscriber, nothing changes: `logger::init()` is not called by the library and if you call it yourself it will early-return when a subscriber is already set.
20+
21+
**Derivatives Trading Usds Futures**
22+
23+
### Added (2)
24+
25+
#### REST API
26+
27+
- `rpi_order_book()` (`GET /fapi/v1/rpiDepth`)
28+
29+
#### WebSocket Streams
30+
31+
- `rpi_diff_book_depth_streams()` (`<symbol>@rpiDepth@500ms` stream)
32+
33+
### Changed (2)
34+
35+
#### REST API
36+
37+
- Modified response for `user_commission_rate()` (`GET /dapi/v1/commissionRate`):
38+
- property `rpi_commission_rate` added
39+
40+
#### WebSocket Streams
41+
42+
- Modified `UserDataStreamEventsResponse` for `AlgoUpdate`:
43+
- `o`: property `rm` added
44+
45+
**Simple Earn**
46+
47+
### Changed (2)
48+
49+
- Modified response for `get_bfusd_account()` (`GET /sapi/v1/bfusd/account`):
50+
- property `usdt_profit` added
51+
- property `bfusd_profit` added
52+
- property `total_profit` removed
53+
54+
- Modified response for `get_bfusd_rewards_history()` (`GET /sapi/v1/bfusd/history/rewardsHistory`):
55+
- `rows`.items: property `reward_asset` added
56+
357
## 32.0.0 - 2025-11-20
458

559
**Derivatives Trading Portfolio Margin Pro**

Cargo.toml

Lines changed: 11 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "binance-sdk"
3-
version = "32.0.0"
3+
version = "33.0.0"
44
authors = [ "Binance" ]
55
edition = "2024"
66
resolver = "3"
@@ -1954,6 +1954,11 @@ name = "derivatives_trading_usds_futures_rest_api_market_data_api_recent_trades_
19541954
path = "examples/derivatives_trading_usds_futures/rest_api/market_data_api/recent_trades_list.rs"
19551955
required-features = [ "derivatives_trading_usds_futures" ]
19561956

1957+
[[example]]
1958+
name = "derivatives_trading_usds_futures_rest_api_market_data_api_rpi_order_book"
1959+
path = "examples/derivatives_trading_usds_futures/rest_api/market_data_api/rpi_order_book.rs"
1960+
required-features = [ "derivatives_trading_usds_futures" ]
1961+
19571962
[[example]]
19581963
name = "derivatives_trading_usds_futures_rest_api_market_data_api_symbol_order_book_ticker"
19591964
path = "examples/derivatives_trading_usds_futures/rest_api/market_data_api/symbol_order_book_ticker.rs"
@@ -2349,6 +2354,11 @@ name = "derivatives_trading_usds_futures_websocket_streams_partial_book_depth_st
23492354
path = "examples/derivatives_trading_usds_futures/websocket_streams/partial_book_depth_streams.rs"
23502355
required-features = [ "derivatives_trading_usds_futures" ]
23512356

2357+
[[example]]
2358+
name = "derivatives_trading_usds_futures_websocket_streams_rpi_diff_book_depth_streams"
2359+
path = "examples/derivatives_trading_usds_futures/websocket_streams/rpi_diff_book_depth_streams.rs"
2360+
required-features = [ "derivatives_trading_usds_futures" ]
2361+
23522362
[[example]]
23532363
name = "dual_investment_rest_api_market_data_api_get_dual_investment_product_list"
23542364
path = "examples/dual_investment/rest_api/market_data_api/get_dual_investment_product_list.rs"
@@ -2694,36 +2704,6 @@ name = "margin_trading_rest_api_trade_api_small_liability_exchange"
26942704
path = "examples/margin_trading/rest_api/trade_api/small_liability_exchange.rs"
26952705
required-features = [ "margin_trading" ]
26962706

2697-
[[example]]
2698-
name = "margin_trading_rest_api_trade_data_stream_api_close_isolated_margin_user_data_stream"
2699-
path = "examples/margin_trading/rest_api/trade_data_stream_api/close_isolated_margin_user_data_stream.rs"
2700-
required-features = [ "margin_trading" ]
2701-
2702-
[[example]]
2703-
name = "margin_trading_rest_api_trade_data_stream_api_close_margin_user_data_stream"
2704-
path = "examples/margin_trading/rest_api/trade_data_stream_api/close_margin_user_data_stream.rs"
2705-
required-features = [ "margin_trading" ]
2706-
2707-
[[example]]
2708-
name = "margin_trading_rest_api_trade_data_stream_api_keepalive_isolated_margin_user_data_stream"
2709-
path = "examples/margin_trading/rest_api/trade_data_stream_api/keepalive_isolated_margin_user_data_stream.rs"
2710-
required-features = [ "margin_trading" ]
2711-
2712-
[[example]]
2713-
name = "margin_trading_rest_api_trade_data_stream_api_keepalive_margin_user_data_stream"
2714-
path = "examples/margin_trading/rest_api/trade_data_stream_api/keepalive_margin_user_data_stream.rs"
2715-
required-features = [ "margin_trading" ]
2716-
2717-
[[example]]
2718-
name = "margin_trading_rest_api_trade_data_stream_api_start_isolated_margin_user_data_stream"
2719-
path = "examples/margin_trading/rest_api/trade_data_stream_api/start_isolated_margin_user_data_stream.rs"
2720-
required-features = [ "margin_trading" ]
2721-
2722-
[[example]]
2723-
name = "margin_trading_rest_api_trade_data_stream_api_start_margin_user_data_stream"
2724-
path = "examples/margin_trading/rest_api/trade_data_stream_api/start_margin_user_data_stream.rs"
2725-
required-features = [ "margin_trading" ]
2726-
27272707
[[example]]
27282708
name = "margin_trading_rest_api_transfer_api_get_cross_margin_transfer_history"
27292709
path = "examples/margin_trading/rest_api/transfer_api/get_cross_margin_transfer_history.rs"
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
use anyhow::{Context, Result};
2+
use std::env;
3+
use tracing::info;
4+
5+
use binance_sdk::config::ConfigurationRestApi;
6+
use binance_sdk::derivatives_trading_usds_futures::{
7+
DerivativesTradingUsdsFuturesRestApi, rest_api::RpiOrderBookParams,
8+
};
9+
10+
#[tokio::main]
11+
async fn main() -> Result<()> {
12+
// Load credentials from env
13+
let api_key = env::var("API_KEY").context("API_KEY must be set")?;
14+
let api_secret = env::var("API_SECRET").context("API_SECRET must be set")?;
15+
16+
// Build REST config
17+
let rest_conf = ConfigurationRestApi::builder()
18+
.api_key(api_key)
19+
.api_secret(api_secret)
20+
.build()?;
21+
22+
// Create the DerivativesTradingUsdsFutures REST API client
23+
let rest_client = DerivativesTradingUsdsFuturesRestApi::production(rest_conf);
24+
25+
// Setup the API parameters
26+
let params = RpiOrderBookParams::builder("symbol_example".to_string()).build()?;
27+
28+
// Make the API call
29+
let response = rest_client
30+
.rpi_order_book(params)
31+
.await
32+
.context("rpi_order_book request failed")?;
33+
34+
info!(?response.rate_limits, "rpi_order_book rate limits");
35+
let data = response.data().await?;
36+
info!(?data, "rpi_order_book data");
37+
38+
Ok(())
39+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// Class name: websocket_market_streams_api
2+
use anyhow::{Context, Result};
3+
use tokio::time::{Duration, sleep};
4+
use tracing::info;
5+
6+
use binance_sdk::config::ConfigurationWebsocketStreams;
7+
use binance_sdk::derivatives_trading_usds_futures::{
8+
DerivativesTradingUsdsFuturesWsStreams, websocket_streams::RpiDiffBookDepthStreamsParams,
9+
};
10+
11+
#[tokio::main]
12+
async fn main() -> Result<()> {
13+
// Build WebSocket Streams config
14+
let ws_streams_conf = ConfigurationWebsocketStreams::builder().build()?;
15+
16+
// Create the DerivativesTradingUsdsFutures WebSocket Streams client
17+
let ws_streams_client = DerivativesTradingUsdsFuturesWsStreams::production(ws_streams_conf);
18+
19+
// Connect to WebSocket
20+
let connection = ws_streams_client
21+
.connect()
22+
.await
23+
.context("Failed to connect to WebSocket Streams")?;
24+
25+
// Setup the stream parameters
26+
let params = RpiDiffBookDepthStreamsParams::builder("btcusdt".to_string()).build()?;
27+
28+
// Subscribe to the stream
29+
let stream = connection
30+
.rpi_diff_book_depth_streams(params)
31+
.await
32+
.context("Failed to subscribe to the stream")?;
33+
34+
// Register callback for incoming messages
35+
stream.on_message(|data| {
36+
info!("{:?}", data);
37+
});
38+
39+
// Disconnect after 20 seconds
40+
sleep(Duration::from_secs(20)).await;
41+
connection
42+
.disconnect()
43+
.await
44+
.context("Failed to disconnect WebSocket client")?;
45+
46+
Ok(())
47+
}

src/algo/README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ This module provides the official Rust client for Binance's Algo Trading REST AP
1515
- [Installation](#installation)
1616
- [Documentation](#documentation)
1717
- [REST APIs](#rest-apis)
18+
- [Logging](#logging)
1819
- [Testing](#testing)
1920
- [Migration Guide](#migration-guide)
2021
- [Contributing](#contributing)
@@ -137,6 +138,26 @@ Errors are represented by the following types:
137138

138139
See the [Error Handling example](./docs/rest_api/error-handling.md) for detailed usage. Refer to the [`error`](../common/errors.rs) module for more information.
139140

141+
## Logging
142+
143+
This crate ships with an optional default logger that you can enable with a single call:
144+
145+
```rust
146+
use binance_sdk::logger;
147+
148+
fn main() {
149+
// Initialize the default logger once at the start of your application
150+
logger::init();
151+
152+
// ... rest of your code
153+
}
154+
```
155+
156+
The logger integrates with the Rust `tracing` ecosystem and behaves as follows:
157+
158+
- If **another global subscriber is already set**, `logger::init()` is a no-op and does not override your existing logging setup.
159+
- If **no subscriber is set yet**, it installs the crate’s default global subscriber (with sensible defaults) so you immediately get structured logs from the connector.
160+
140161
## Testing
141162

142163
To run the tests for the Algo module:

src/algo/mod.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
pub mod rest_api;
22

33
use crate::common::{
4-
config::ConfigurationRestApi, constants::ALGO_REST_API_PROD_URL, logger,
5-
utils::build_user_agent,
4+
config::ConfigurationRestApi, constants::ALGO_REST_API_PROD_URL, utils::build_user_agent,
65
};
76

87
/// Represents the Algo REST API client for interacting with the Binance Algo REST API.
@@ -24,8 +23,6 @@ impl AlgoRestApi {
2423
/// A new REST API client configured with the provided settings
2524
#[must_use]
2625
pub fn from_config(mut config: ConfigurationRestApi) -> rest_api::RestApi {
27-
logger::init();
28-
2926
config.user_agent = build_user_agent("algo");
3027
if config.base_path.is_none() {
3128
config.base_path = Some(ALGO_REST_API_PROD_URL.to_string());

src/c2c/README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ This module provides the official Rust client for Binance's C2C API, enabling de
1515
- [Installation](#installation)
1616
- [Documentation](#documentation)
1717
- [REST APIs](#rest-apis)
18+
- [Logging](#logging)
1819
- [Testing](#testing)
1920
- [Migration Guide](#migration-guide)
2021
- [Contributing](#contributing)
@@ -137,6 +138,26 @@ Errors are represented by the following types:
137138

138139
See the [Error Handling example](./docs/rest_api/error-handling.md) for detailed usage. Refer to the [`error`](../common/errors.rs) module for more information.
139140

141+
## Logging
142+
143+
This crate ships with an optional default logger that you can enable with a single call:
144+
145+
```rust
146+
use binance_sdk::logger;
147+
148+
fn main() {
149+
// Initialize the default logger once at the start of your application
150+
logger::init();
151+
152+
// ... rest of your code
153+
}
154+
```
155+
156+
The logger integrates with the Rust `tracing` ecosystem and behaves as follows:
157+
158+
- If **another global subscriber is already set**, `logger::init()` is a no-op and does not override your existing logging setup.
159+
- If **no subscriber is set yet**, it installs the crate’s default global subscriber (with sensible defaults) so you immediately get structured logs from the connector.
160+
140161
## Testing
141162

142163
To run the tests for the C2C module:

src/c2c/mod.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
pub mod rest_api;
22

33
use crate::common::{
4-
config::ConfigurationRestApi, constants::C2C_REST_API_PROD_URL, logger, utils::build_user_agent,
4+
config::ConfigurationRestApi, constants::C2C_REST_API_PROD_URL, utils::build_user_agent,
55
};
66

77
/// Represents the C2C REST API client for interacting with the Binance C2C REST API.
@@ -23,8 +23,6 @@ impl C2CRestApi {
2323
/// A new REST API client configured with the provided settings
2424
#[must_use]
2525
pub fn from_config(mut config: ConfigurationRestApi) -> rest_api::RestApi {
26-
logger::init();
27-
2826
config.user_agent = build_user_agent("c2c");
2927
if config.base_path.is_none() {
3028
config.base_path = Some(C2C_REST_API_PROD_URL.to_string());

src/common/logger.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,18 @@ static INIT_LOG: Once = Once::new();
1212
/// The initialization is performed only once using a `Once` synchronization primitive
1313
/// to ensure thread-safe global subscriber setup.
1414
pub fn init() {
15-
let filter = EnvFilter::try_from_default_env().unwrap_or_else(|_| EnvFilter::new("info"));
15+
INIT_LOG.call_once(|| {
16+
if tracing::dispatcher::has_been_set() {
17+
return;
18+
}
1619

17-
let fmt_layer = fmt::layer()
18-
.with_target(false)
19-
.with_thread_ids(true)
20-
.with_thread_names(true);
20+
let filter = EnvFilter::try_from_default_env().unwrap_or_else(|_| EnvFilter::new("info"));
21+
22+
let fmt_layer = fmt::layer()
23+
.with_target(false)
24+
.with_thread_ids(true)
25+
.with_thread_names(true);
2126

22-
INIT_LOG.call_once(|| {
2327
let subscriber = Registry::default().with(filter).with(fmt_layer);
2428
let _ = tracing::subscriber::set_global_default(subscriber);
2529
});

0 commit comments

Comments
 (0)