Expand description
Fixed-window rate limiting for the Derive adapter.
Derive refills every request allowance in discrete five-second windows, not
one token at a time. A Trader can spend a full burst of tps * 5 matching
requests inside one window. The next request must then wait for the window
boundary; nothing refills before it.
The buckets and their allowances:
- Matching writes draw on two independent allowances: account-wide matching and per-instrument matching.
private/cancel_alland unscopedprivate/cancel_by_labelhave custom quotas.- REST non-matching requests use a flat per-IP allowance; authenticated WebSocket non-matching requests use a separate one.
See https://docs.derive.xyz/reference/rate-limits.
FixedWindowLimiter keeps one packed atomic word per bucket key holding
the window index and the count consumed from it, so a check-and-consume is
a single compare-and-swap. Windows align to limiter creation because the
venue’s own window phase cannot be observed from the client. A wait is
therefore at most one full window, and the long-run average rate stays at
the venue allowance. A burst can still straddle a venue window boundary;
the venue then rejects the request outright. That rejection is definitive
(surfaced as an OrderRejected), not ambiguous.
The limiter is generic over the nautilus_network clocks: tests drive it
deterministically with FakeRelativeClock, production uses
[MonotonicClock].
Constants§
- DERIVE_
CANCEL_ ALL_ RATE_ KEY - Rate-limit bucket key for
private/cancel_allrequests. - DERIVE_
CANCEL_ ALL_ TPS - Custom allowance for
private/cancel_all(requests per second). - DERIVE_
CANCEL_ BY_ LABEL_ RATE_ KEY - Rate-limit bucket key for unscoped
private/cancel_by_labelrequests. - DERIVE_
CANCEL_ BY_ LABEL_ TPS - Custom allowance for unscoped
private/cancel_by_label(requests per second). - DERIVE_
DEFAULT_ MATCHING_ TPS - Default matching-engine allowance for a Trader-tier account, in requests
per second. Market Maker accounts negotiate higher limits via
crate::config::DeriveExecutionClientConfig’smax_matching_requests_per_secondfield. - DERIVE_
DEFAULT_ PER_ INSTRUMENT_ MATCHING_ TPS - Default per-instrument matching allowance for a Trader-tier account, in
requests per second. Market Maker accounts negotiate higher limits via
crate::config::DeriveExecutionClientConfig’smax_per_instrument_matching_requests_per_secondfield. The account-wide override never inflates this bucket. - DERIVE_
MATCHING_ RATE_ KEY - Rate-limit bucket key for matching-engine requests (order create/cancel/replace).
- DERIVE_
NON_ MATCHING_ RATE_ KEY - Rate-limit bucket key for non-matching requests (reads, subscriptions, login).
- DERIVE_
NON_ MATCHING_ TPS - Flat REST non-matching allowance per IP (requests per second).
- DERIVE_
RATE_ BURST_ MULTIPLIER - Burst multiplier: each window admits five seconds’ worth of requests.
- DERIVE_
RATE_ WINDOW_ SECS - Fixed-window length: Derive refills every allowance discretely at window boundaries spaced five seconds apart.
- DERIVE_
WEBSOCKET_ NON_ MATCHING_ TPS - Default authenticated WebSocket non-matching allowance for a Trader account.