Skip to main content

Module rate_limiter

Module rate_limiter 

Source
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 weight
  • X-MBX-ORDER-COUNT-*: Current order count
  • Retry-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§

RateLimitInfo
Rate limit information extracted from response headers.
WeightRateLimiter
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%).