pub struct WeightRateLimiter { /* private fields */ }Expand description
Weight-based rate limiter for Binance API.
Tracks API usage based on response headers and provides throttling recommendations to avoid hitting rate limits.
Implementations§
Source§impl WeightRateLimiter
impl WeightRateLimiter
Sourcepub fn with_limits(
weight_limit_1m: u64,
order_limit_10s: u64,
order_limit_1d: u64,
) -> Self
pub fn with_limits( weight_limit_1m: u64, order_limit_10s: u64, order_limit_1d: u64, ) -> Self
Creates a new rate limiter with custom limits.
§Arguments
weight_limit_1m- Weight limit per minuteorder_limit_10s- Order limit per 10 secondsorder_limit_1d- Order limit per day
Sourcepub fn update(&self, info: RateLimitInfo)
pub fn update(&self, info: RateLimitInfo)
Updates the rate limiter with information from response headers.
§Arguments
info- Rate limit information extracted from headers
Sourcepub fn set_ip_banned(&self, duration: Duration)
pub fn set_ip_banned(&self, duration: Duration)
Sourcepub fn is_ip_banned(&self) -> bool
pub fn is_ip_banned(&self) -> bool
Returns true if the IP is currently banned.
Sourcepub fn should_throttle(&self) -> bool
pub fn should_throttle(&self) -> bool
Returns true if we should throttle requests.
Throttling is recommended when:
- We’re in a Retry-After period
- Weight usage exceeds 80% of the limit
- Order count exceeds 80% of the limit
- IP is banned
Sourcepub fn wait_duration(&self) -> Option<Duration>
pub fn wait_duration(&self) -> Option<Duration>
Returns the recommended wait duration before making the next request.
Returns None if no waiting is needed.
Sourcepub fn used_weight(&self) -> u64
pub fn used_weight(&self) -> u64
Returns the current used weight.
Sourcepub fn weight_limit(&self) -> u64
pub fn weight_limit(&self) -> u64
Returns the weight limit.
Sourcepub fn order_count_10s(&self) -> u64
pub fn order_count_10s(&self) -> u64
Returns the current order count (10s window).
Sourcepub fn order_count_1d(&self) -> u64
pub fn order_count_1d(&self) -> u64
Returns the current order count (daily).
Sourcepub fn order_limit_1d(&self) -> u64
pub fn order_limit_1d(&self) -> u64
Returns the order limit per day.
Sourcepub fn weight_usage_ratio(&self) -> f64
pub fn weight_usage_ratio(&self) -> f64
Returns the weight usage percentage (0.0 to 1.0).
Trait Implementations§
Source§impl Debug for WeightRateLimiter
impl Debug for WeightRateLimiter
Auto Trait Implementations§
impl !Freeze for WeightRateLimiter
impl RefUnwindSafe for WeightRateLimiter
impl Send for WeightRateLimiter
impl Sync for WeightRateLimiter
impl Unpin for WeightRateLimiter
impl UnsafeUnpin for WeightRateLimiter
impl UnwindSafe for WeightRateLimiter
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more