Skip to content

Conversation

@nicolad
Copy link
Member

@nicolad nicolad commented Sep 15, 2025

Introduce a weighted, minute-bucket rate limiter for Hyperliquid REST and wire it into Info/Exchange calls. Supports base weights per endpoint, post-response extra debits (for item-scaled endpoints), batch-aware Exchange costs, and bounded retries with full-jitter + Retry-After handling. Surfaces structured RateLimit { scope, weight, retry_after_ms } errors.

Why not reuse NT’s limiter?

  • NT’s Quota is uniform per request; Hyperliquid requires weighted charges and post-response debits.
  • No batch-size awareness in Quota (Exchange: 1 + floor(n/40)).
  • Adapter needs minute bucket + anti-stampede semantics and exchange-specific weight tables.

Implementation highlights

  • WeightedLimiter::per_minute(1200): token bucket; acquire(weight), debit_extra(extra), snapshot().
  • Weights: info_base_weight, info_extra_weight (largest array, +1/20; candleSnapshot +1/60); exchange_weight.
  • Backoff: full-jitter (base=125ms, cap=5s), honor Retry-After; tiny re-acquire to defuse minute rollovers.
  • Defaults in HyperliquidHttpClient; optional with_rate_limits() tuning.

@nicolad nicolad requested a review from cjdsellers September 15, 2025 11:37
@nicolad nicolad self-assigned this Sep 15, 2025
@nicolad nicolad added the rust Relating to the Rust core label Sep 15, 2025
@cjdsellers cjdsellers changed the title Hyperliquid: implement comprehensive weighted rate limiting for REST API Implement Hyperliquid weighted rate limiter for REST API Sep 15, 2025
Copy link
Member

@cjdsellers cjdsellers left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @nicolad, great progress here. We need this because the existing GCRA style rate limiter doesn’t match Hyperliquid’s requirements, and what you’ve implemented here aligns with exactly what's needed.

@cjdsellers cjdsellers merged commit 3d941a3 into develop Sep 15, 2025
13 checks passed
@cjdsellers cjdsellers deleted the hyperliquid-7 branch September 15, 2025 20:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

rust Relating to the Rust core

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants