Skip to main content

Module rate_limit

Module rate_limit 

Source
Expand description

Rate-limit quotas and keys for the Derive adapter.

Derive runs a fixed-window limiter that replenishes the request allowance every five seconds, splitting traffic into matching-engine actions (order create/cancel/replace) and everything else (“non-matching”: market-data reads, channel subscriptions, login). Matching limits are per account and tiered (Trader vs Market Maker); the non-matching limit is a flat per-IP allowance. See https://docs.derive.xyz/reference/rate-limits.

The nautilus_network limiter is GCRA-based, so each quota is expressed as a sustained per-second rate with a burst capacity of five seconds’ worth of cells. That reproduces Derive’s “5x burst, replenished every 5 seconds” model: a full burst of tps * 5 cells drains, then refills one cell every 1 / tps seconds (five seconds to refill the whole burst).

Constants§

DERIVE_DEFAULT_MATCHING_TPS
Default matching-engine allowance for a Trader-tier account (requests per second). Market Maker accounts negotiate higher limits and raise this via crate::config::DeriveExecClientConfig::max_matching_requests_per_second.
DERIVE_MATCHING_RATE_KEY
Rate-limit key for matching-engine requests (order create/cancel/replace).
DERIVE_NON_MATCHING_RATE_KEY
Rate-limit key for non-matching requests (reads, subscriptions, login).
DERIVE_NON_MATCHING_TPS
Flat non-matching allowance per IP (requests per second).
DERIVE_RATE_BURST_MULTIPLIER
Burst multiplier: Derive permits five seconds’ worth of requests in a single burst before the fixed window replenishes.

Functions§

matching_quota
Builds the matching-engine quota for max_requests_per_second, falling back to DERIVE_DEFAULT_MATCHING_TPS when unset or zero.
non_matching_quota
Builds the flat non-matching quota (DERIVE_NON_MATCHING_TPS).