Skip to content

fix: cherry-pick 429 rate limiting fix with coin naming convention#25443

Merged
joaoloureirop merged 3 commits intorelease/7.62.2from
fix/perps/ratelimit-hotfix
Jan 30, 2026
Merged

fix: cherry-pick 429 rate limiting fix with coin naming convention#25443
joaoloureirop merged 3 commits intorelease/7.62.2from
fix/perps/ratelimit-hotfix

Conversation

@abretonc7s
Copy link
Copy Markdown
Contributor

@abretonc7s abretonc7s commented Jan 30, 2026

Description

Cherry-pick of commit 425beae (Nick's 429 rate limiting fix) to release/7.62.2 branch.

This hotfix addresses HyperLiquid WebSocket rate limiting issues (429 errors) that occur during rapid market switching or TP/SL updates. The fix introduces cache-first patterns to reduce API weight and avoid hitting rate limits.

Key changes:

  • Add optional position parameter to updatePositionTPSL to skip REST API fetch when WebSocket data is available
  • Implement getOrFetchPrice helper for WebSocket-first price retrieval (0 weight vs 20 weight)
  • Add atomic cache getter getOrdersCacheIfInitialized() to prevent race conditions
  • Add getOrFetchFills for cache-first fills retrieval
  • Move positionOpenedTimestamp calculation into useHasExistingPosition hook
  • Add currentPositionRef sync in PerpsMarketDetailsView to prevent stale closure issues

Conflict resolution notes:
The main branch uses symbol naming convention while release/7.62.2 uses coin. All conflicts were resolved by keeping the coin naming convention while adopting the cache-first optimization patterns.

Changelog

CHANGELOG entry: Fixed rate limiting issues (429 errors) when rapidly switching markets or updating TP/SL orders

Related issues

Fixes: Rate limiting issues on HyperLiquid API during rapid market navigation

Manual testing steps

Feature: Rate limiting prevention for Perps

  Scenario: User rapidly switches between markets
    Given user has the Perps feature enabled
    And user is viewing a market details page

    When user rapidly navigates between different markets (BTC -> ETH -> SOL -> BTC)
    Then no 429 rate limit errors should appear
    And market data should load correctly for each market

  Scenario: User updates TP/SL via stop loss prompt banner
    Given user has an open position without stop loss
    And the stop loss prompt banner is visible

    When user taps "Set Stop Loss" on the banner
    Then the stop loss should be set successfully
    And no rate limit errors should occur

  Scenario: User edits existing TP/SL on a position
    Given user has an open position with TP/SL set

    When user navigates to modify TP/SL
    And user updates the stop loss price
    Then the update should succeed without 429 errors

Screenshots/Recordings

Before

N/A - Bug fix for rate limiting, no visual changes

After

N/A - Bug fix for rate limiting, no visual changes

Pre-merge author checklist

Pre-merge reviewer checklist

  • I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed).
  • I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots.

Note

Medium Risk
Touches perps trading/provider logic (updatePositionTPSL, order/price/fill retrieval) and async UI state around stop-loss actions, so regressions could impact TP/SL updates or stale-data handling, but changes are bounded and add explicit fallbacks/tests.

Overview
Goal: reduce HyperLiquid REST API weight (and 429s) during rapid market switching and TP/SL operations by preferring WebSocket caches.

Adds cache-first primitives in HyperLiquidSubscriptionService (fills cache + atomic getOrdersCacheIfInitialized) and HyperLiquidProvider (getOrFetchPrice, getOrFetchFills), and refactors provider call sites to use these helpers with stricter invalid-price validation and single-DEX REST fallbacks.

Updates TP/SL flow to pass live WebSocket position into updatePositionTPSL (avoiding a REST positions fetch), uses cached orders to cancel existing TP/SL when available, and surfaces partial-failure feedback in PerpsOrderView when order succeeds but TP/SL update fails.

Moves positionOpenedTimestamp derivation into useHasExistingPosition (WebSocket fills first, REST historical fallback), and hardens PerpsMarketDetailsView stop-loss banner interactions against stale closures/market switches; the banner UI switches from a Switch to a "Set" button with a delayed success checkmark + fade-out. Tests and test IDs are updated accordingly.

Written by Cursor Bugbot for commit 0edee81. This will update automatically on new commits. Configure here.

Cherry-pick commit 425beae (Nick's 429 rate limiting fix) adapted for
release/7.62.2 branch which uses 'coin' naming instead of 'symbol'.

Key changes:
- Add cache-first patterns in HyperLiquidProvider to reduce API weight
- Add optional position param to updatePositionTPSL to skip REST fetch
- Add atomic cache getter getOrdersCacheIfInitialized() to prevent race conditions
- Add getOrFetchPrice helper for WebSocket-first price retrieval
- Add getOrFetchFills for cache-first fills retrieval
- Add positionOpenedTimestamp to useHasExistingPosition hook
- Sync currentPositionRef in PerpsMarketDetailsView for stale closure prevention

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@abretonc7s abretonc7s requested a review from a team as a code owner January 30, 2026 14:38
@github-actions
Copy link
Copy Markdown
Contributor

CLA Signature Action: All authors have signed the CLA. You may need to manually re-run the blocking PR check if it doesn't pass in a few minutes.

@metamaskbot metamaskbot added the team-perps Perps team label Jan 30, 2026
@abretonc7s abretonc7s marked this pull request as draft January 30, 2026 14:43
@abretonc7s abretonc7s added the skip-sonar-cloud Only used for bypassing sonar cloud when failures are not relevant to the changes. label Jan 30, 2026
@abretonc7s abretonc7s marked this pull request as ready for review January 30, 2026 15:03
@github-actions
Copy link
Copy Markdown
Contributor

🔍 Smart E2E Test Selection

⏭️ Smart E2E selection skipped - base branch is not main (base: release/7.62.2)

All E2E tests pre-selected.

View GitHub Actions results

Copy link
Copy Markdown
Contributor

@aganglada aganglada left a comment

Choose a reason for hiding this comment

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

Tested, cannot repro 🙌

Copy link
Copy Markdown

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

// Apply symbol filter to REST results for consistent API behavior
// Note: getOrderFills doesn't support symbol filtering natively
return this.filterFills(restFills, params);
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Public method getOrFetchFills is never called in production

Low Severity

The public method getOrFetchFills is added to the IPerpsProvider interface and fully implemented with supporting infrastructure (filterFills helper, GetOrFetchFillsParams type), but it's only called in test files—never in actual production code. This adds dead code that increases maintenance burden. The method's documentation states it's meant to "prevent 429 errors during rapid market switching by reusing cached fills," but no code path actually invokes it.

Additional Locations (1)

Fix in Cursor Fix in Web

@sonarqubecloud
Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
77.4% Coverage on New Code (required ≥ 80%)

See analysis details on SonarQube Cloud

@joaoloureirop joaoloureirop enabled auto-merge (squash) January 30, 2026 16:07
@joaoloureirop joaoloureirop merged commit 03f318a into release/7.62.2 Jan 30, 2026
162 of 170 checks passed
@joaoloureirop joaoloureirop deleted the fix/perps/ratelimit-hotfix branch January 30, 2026 16:23
@github-actions github-actions bot locked and limited conversation to collaborators Jan 30, 2026
@metamaskbot metamaskbot added the release-7.62.2 Issue or pull request that will be included in release 7.62.2 label Feb 3, 2026
@metamaskbot
Copy link
Copy Markdown
Collaborator

No release label on PR. Adding release label release-7.62.2 on PR, as PR was cherry-picked in branch 7.62.2.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

release-7.62.2 Issue or pull request that will be included in release 7.62.2 size-XL skip-sonar-cloud Only used for bypassing sonar cloud when failures are not relevant to the changes. team-perps Perps team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants