rustrade_execution/client/binance/mod.rs
1//! Binance execution clients.
2//!
3//! - [`BinanceSpot`] — Binance Spot `ExecutionClient` (REST + signed WebSocket API).
4//! - [`BinanceMargin`] — Binance Cross Margin `ExecutionClient` (REST orders/queries +
5//! a hand-rolled `userListenToken` user-data stream). Configured via
6//! [`BinanceMarginConfig`]/[`MarginSideEffect`].
7//!
8//! Both clients share exchange-agnostic infrastructure (reconnect/backoff,
9//! rate-limit tracking, event deduplication, error parsing, and the
10//! Binance-string parsers) from the `shared` module, so resilience behaviour is
11//! implemented once and reused rather than duplicated per client.
12//!
13//! # Logging: `binance_sdk` writes request credentials at `DEBUG`
14//!
15//! Both clients run on the `binance-sdk` crate, whose WebSocket API client logs every outgoing
16//! request at `DEBUG`, after it has been signed:
17//!
18//! - [`BinanceSpot`] places and cancels orders and subscribes to its user-data stream with signed
19//! requests, so each of those log lines carries the account's **API key** and the request's
20//! **signature**.
21//! - [`BinanceMargin`] subscribes to its user-data stream with an unsigned request whose only
22//! credential is the **listen token**, which is logged in the same way.
23//!
24//! The API secret and private key are never logged. The SDK logs these lines with `tracing`
25//! under the `binance_sdk` target.
26//!
27//! This library installs no subscriber, so what reaches your logs is decided by the filter your
28//! application builds. A bare `RUST_LOG=debug` enables these lines. To keep them out by default,
29//! seed a `binance_sdk=info` directive **before** your own:
30//!
31//! ```
32//! use tracing_subscriber::EnvFilter;
33//!
34//! let user = std::env::var("RUST_LOG").unwrap_or_else(|_| "info".to_owned());
35//! let filter = EnvFilter::try_new(format!("binance_sdk=info,{user}"))?;
36//! # Ok::<(), Box<dyn std::error::Error>>(())
37//! ```
38//!
39//! `EnvFilter` applies the most specific matching directive, and a later directive for the same
40//! target replaces an earlier one. So a bare `debug` cannot lift the seeded `binance_sdk=info`,
41//! while an explicit `RUST_LOG=binance_sdk=debug` still can when you need the SDK's traffic.
42//! Adding the directive *after* reading the environment, as in
43//! `EnvFilter::from_default_env().add_directive(..)`, gets this backwards: it silently overrides
44//! an explicit request.
45
46mod margin;
47mod shared;
48mod spot;
49
50pub use margin::{BinanceMargin, BinanceMarginConfig, MarginSideEffect};
51pub use spot::{BinanceSpot, BinanceSpotConfig, BinanceSpotConfigError};