Expand description
Binance rate limiter implementation.
This module provides weight-based rate limiting for Binance API requests. Binance uses a weight system where different endpoints consume different amounts of weight, and there are separate limits for different categories.
§Rate Limit Categories
- Request Weight: General API request limit (default: 1200/minute for spot)
- Order Count: Order placement limit (default: 10 orders/second, 100000/day)
- Raw Requests: Raw request count limit
§Response Headers
Binance returns rate limit information in response headers:
X-MBX-USED-WEIGHT-*: Current used weightX-MBX-ORDER-COUNT-*: Current order countRetry-After: Seconds to wait when rate limited
§Example
use ccxt_exchanges::binance::rate_limiter::{WeightRateLimiter, RateLimitInfo};
let limiter = WeightRateLimiter::new();
// Update from response headers
let info = RateLimitInfo {
used_weight_1m: Some(500),
used_weight_1s: None,
order_count_10s: Some(5),
order_count_1d: Some(1000),
retry_after: None,
};
limiter.update(info);
// Check if we should throttle
if limiter.should_throttle() {
// Wait before making more requests
}Structs§
- Rate
Limit Info - Rate limit information extracted from response headers.
- Weight
Rate Limiter - Weight-based rate limiter for Binance API.
Constants§
- DEFAULT_
ORDER_ LIMIT_ 1D - Default order count limit per day.
- DEFAULT_
ORDER_ LIMIT_ 10S - Default order count limit per 10 seconds.
- DEFAULT_
WEIGHT_ LIMIT_ 1M - Default weight limit per minute for spot API.
- DEFAULT_
WEIGHT_ LIMIT_ 1S - Default weight limit per second.
- THROTTLE_
THRESHOLD - Threshold percentage at which to start throttling (80%).