pub struct GroupRateLimiter { /* private fields */ }Expand description
Group-based rate limiter: multiple independent pools keyed by name.
Each group is an independent WeightRateLimiter with its own max/window.
Requests are routed to the appropriate group by the connector.
§Used by exchanges:
- Phemex: CONTRACT, SPOTORDER, OTHERS groups
- Upbit: market, account, order groups
- Kraken Futures: derivatives (500/10s), history (100/600s)
Implementations§
Source§impl GroupRateLimiter
impl GroupRateLimiter
Sourcepub fn add_group(
&mut self,
name: &'static str,
max_weight: u32,
window: Duration,
)
pub fn add_group( &mut self, name: &'static str, max_weight: u32, window: Duration, )
Add a named rate limit group
§Arguments
name- Group name (must be'staticstr, e.g."public")max_weight- Maximum total weight for this group’s windowwindow- Time window duration for this group
Sourcepub fn try_acquire(&mut self, group: &str, weight: u32) -> bool
pub fn try_acquire(&mut self, group: &str, weight: u32) -> bool
Try to acquire weight from a specific group
§Returns
trueif weight is within the group’s limit (or group is unknown)falseif adding this weight would exceed the group’s limit
Sourcepub fn time_until_ready(&mut self, group: &str, weight: u32) -> Duration
pub fn time_until_ready(&mut self, group: &str, weight: u32) -> Duration
Get wait time for a specific group
§Returns
Duration::ZEROif the group is unknown or request fits within limits- Otherwise, the time to wait until enough weight capacity is available
Sourcepub fn update_from_server(&mut self, group: &str, used_weight: u32)
pub fn update_from_server(&mut self, group: &str, used_weight: u32)
Update server-reported used weight for a specific group
§Arguments
group- Group nameused_weight- Current used weight reported by server for this group
Sourcepub fn group_stats(&mut self, group: &str) -> Option<(u32, u32)>
pub fn group_stats(&mut self, group: &str) -> Option<(u32, u32)>
Get (current_weight, max_weight) for a specific group
Returns None if the group does not exist.
Sourcepub fn all_stats(&mut self) -> Vec<(&str, u32, u32)>
pub fn all_stats(&mut self) -> Vec<(&str, u32, u32)>
Get stats for all groups as Vec of (name, current_weight, max_weight)
Sourcepub fn primary_stats(&mut self) -> (u32, u32)
pub fn primary_stats(&mut self) -> (u32, u32)
Get primary group stats for backwards-compatible display
Returns (current_weight, max_weight) of an arbitrary group,
or (0, 0) when no groups have been added.
Trait Implementations§
Source§impl Clone for GroupRateLimiter
impl Clone for GroupRateLimiter
Source§fn clone(&self) -> GroupRateLimiter
fn clone(&self) -> GroupRateLimiter
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for GroupRateLimiter
impl Debug for GroupRateLimiter
Auto Trait Implementations§
impl Freeze for GroupRateLimiter
impl RefUnwindSafe for GroupRateLimiter
impl Send for GroupRateLimiter
impl Sync for GroupRateLimiter
impl Unpin for GroupRateLimiter
impl UnsafeUnpin for GroupRateLimiter
impl UnwindSafe for GroupRateLimiter
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