Skip to main content

GroupRateLimiter

Struct GroupRateLimiter 

Source
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

Source

pub fn new() -> Self

Create a new empty group rate limiter

Source

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 'static str, e.g. "public")
  • max_weight - Maximum total weight for this group’s window
  • window - Time window duration for this group
Source

pub fn try_acquire(&mut self, group: &str, weight: u32) -> bool

Try to acquire weight from a specific group

§Returns
  • true if weight is within the group’s limit (or group is unknown)
  • false if adding this weight would exceed the group’s limit
Source

pub fn time_until_ready(&mut self, group: &str, weight: u32) -> Duration

Get wait time for a specific group

§Returns
  • Duration::ZERO if the group is unknown or request fits within limits
  • Otherwise, the time to wait until enough weight capacity is available
Source

pub fn update_from_server(&mut self, group: &str, used_weight: u32)

Update server-reported used weight for a specific group

§Arguments
  • group - Group name
  • used_weight - Current used weight reported by server for this group
Source

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.

Source

pub fn all_stats(&mut self) -> Vec<(&str, u32, u32)>

Get stats for all groups as Vec of (name, current_weight, max_weight)

Source

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

Source§

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)

Performs copy-assignment from source. Read more
Source§

impl Debug for GroupRateLimiter

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for GroupRateLimiter

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more