pub struct AddressRateLimiter { /* private fields */ }Expand description
Tracks the per-address action budget.
Call [record_fill] when a fill is confirmed to grow the budget.
Call [acquire] before every action (not info) request.
Pass is_cancel = true for cancel actions to apply the higher cancel limit.
Pass the actual batch size as count for batched requests.
Implementations§
Source§impl AddressRateLimiter
impl AddressRateLimiter
pub fn new() -> Self
pub fn new_with_budget(initial_budget: u64) -> Self
Sourcepub async fn record_fill(&self, usdc_volume: u64)
pub async fn record_fill(&self, usdc_volume: u64)
Increase the budget by usdc_volume requests (1 request per 1 USDC traded).
Sourcepub async fn acquire(
&self,
count: u64,
is_cancel: bool,
) -> Result<(), RateLimitError>
pub async fn acquire( &self, count: u64, is_cancel: bool, ) -> Result<(), RateLimitError>
Returns Err(RateLimitError) immediately if the address budget is exhausted.
Sourcepub async fn acquire_blocking(&self, count: u64, is_cancel: bool)
pub async fn acquire_blocking(&self, count: u64, is_cancel: bool)
Retries on Err, logging each wait. Resolves once the request is accepted.
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for AddressRateLimiter
impl !RefUnwindSafe for AddressRateLimiter
impl Send for AddressRateLimiter
impl Sync for AddressRateLimiter
impl Unpin for AddressRateLimiter
impl UnsafeUnpin for AddressRateLimiter
impl UnwindSafe for AddressRateLimiter
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