pub struct RateLimiterConfig {
pub default: BucketLimit,
pub overrides: HashMap<RateLimitKey, BucketLimit>,
}Expand description
Configuration for the optional per-endpoint rate limiter.
Pass this via Config::rate_limiter to have the
client pre-flight-check a local bucket before every request and reject calls that would
obviously hit the exchange’s limits.
Bybit tracks a separate limit per endpoint (and, for order endpoints, per category) rather
than one account-wide limit, and batch order endpoints consume one unit of quota per order
in the batch, not one per request
(https://bybit-exchange.github.io/docs/v5/rate-limit). This limiter mirrors that: each
RateLimitKey gets its own independent token bucket and its own server-feedback state,
and every call site reports how many units it actually costs.
Two checks are combined per bucket:
-
Token bucket — tokens refill at the bucket’s
requests_per_second. An initial burst ofbursttokens is available. When the bucket doesn’t have enough tokens for the request’s cost, the request is rejected immediately withError::RateLimited. -
Server feedback — after every response, Bybit’s
X-Bapi-Limit-Status/X-Bapi-Limit-Reset-Timestampheaders are recorded against that response’s bucket. If the server-reported remaining count reaches zero, the next request against that same bucket is rejected withError::RateLimiteduntil the reset window passes, regardless of local token state.
Bybit’s limits vary by account VIP/Pro tier and change over time, so this crate does not
hardcode them: populate overrides yourself from
https://bybit-exchange.github.io/docs/v5/rate-limit, or start from
RateLimiterConfig::bybit_base_tier_defaults and adjust it for your tier.
Fields§
§default: BucketLimitLimit applied to any RateLimitKey not present in overrides.
overrides: HashMap<RateLimitKey, BucketLimit>Per-endpoint (optionally per-category) overrides.
Implementations§
Source§impl RateLimiterConfig
impl RateLimiterConfig
Sourcepub fn uniform(requests_per_second: f64, burst: u32) -> Self
pub fn uniform(requests_per_second: f64, burst: u32) -> Self
A single limit shared by every endpoint, with no per-endpoint overrides.
Equivalent to this crate’s previous, endpoint-unaware rate limiter. Prefer
RateLimiterConfig::bybit_base_tier_defaults for a more accurate starting point.
Sourcepub fn bybit_base_tier_defaults() -> Self
pub fn bybit_base_tier_defaults() -> Self
Starting-point overrides for the base (non-VIP) tier’s most commonly used endpoints, taken from https://bybit-exchange.github.io/docs/v5/rate-limit. Not exhaustive — it only covers the Trade endpoints (where the limit varies sharply by category and, for batch endpoints, is easy to blow through without per-order weighting) plus a couple of high-traffic Account ones. Add your own overrides for anything else, and adjust these if your account has a VIP/Pro tier.
default is set to a conservative 5 req/s, 5 burst for everything not listed here.
Sourcepub fn with_override(self, key: RateLimitKey, limit: BucketLimit) -> Self
pub fn with_override(self, key: RateLimitKey, limit: BucketLimit) -> Self
Set the limit of one bucket.