Skip to content

fix(perps): potential rate limit on close positions cp-7.63.0 cp-7.64.0 cp-7.62.2#25438

Merged
aganglada merged 3 commits intomainfrom
fix/perps/skipcache-order
Jan 30, 2026
Merged

fix(perps): potential rate limit on close positions cp-7.63.0 cp-7.64.0 cp-7.62.2#25438
aganglada merged 3 commits intomainfrom
fix/perps/skipcache-order

Conversation

@abretonc7s
Copy link
Copy Markdown
Contributor

@abretonc7s abretonc7s commented Jan 30, 2026

Description

Complete the 429 rate limiting fix for position management operations. The previous fix (commit 425beaead7) only addressed updatePositionTPSL(). This PR extends the fix to closePosition(), closePositions(), and updateMargin() methods.

Problem: These methods were using skipCache: true which forced REST API calls on every operation, leading to 429 rate limiting errors during prolonged app usage.

Solution:

  • Remove skipCache: true from closePositions() and updateMargin() to use WebSocket cache
  • For closePosition(), add optional position parameter so callers can pass the live WebSocket position directly, avoiding the need to fetch positions entirely
  • Update usePerpsClosePosition hook to pass the position it already has

Changelog

CHANGELOG entry: Fixed rate limiting errors (429) when closing positions or updating margin after prolonged app usage

Related issues

Fixes: Rate limiting issues during position close/margin update operations

Manual testing steps

Feature: Position close without rate limiting

  Scenario: User closes position after prolonged usage
    Given user has the app open for extended period (>30 minutes)
    And user has an open perps position

    When user closes the position
    Then the position closes successfully without 429 errors

  Scenario: User updates margin after prolonged usage
    Given user has the app open for extended period (>30 minutes)
    And user has an open perps position with isolated margin

    When user adjusts the margin
    Then the margin updates successfully without 429 errors

  Scenario: User closes all positions
    Given user has multiple open perps positions

    When user uses "close all positions" feature
    Then all positions close successfully without rate limiting errors

Screenshots/Recordings

Before

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

After

N/A - Bug fix for rate limiting, no UI 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 position-management flows (closePosition, closePositions, updateMargin) and changes them to rely on cached/WebSocket position data, which could surface edge cases if the cache is stale or mismatched, but does not alter core order-placement logic.

Overview
Reduces 429 errors in perps position management by stopping forced REST position refreshes during closePositions and updateMargin, and by updating closePosition to accept an optional live position payload (with a cache-based fallback).

Updates usePerpsClosePosition (and its tests) to pass the already-available position through, avoiding extra getPositions() calls during close flows.

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

@abretonc7s abretonc7s requested a review from a team as a code owner January 30, 2026 13:53
@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 changed the title fix(perps): potential rate limit on close positions fix(perps): potential rate limit on close positions cp-7.63.0 cp-7.64.0 7.62.2 Jan 30, 2026
@aganglada aganglada changed the title fix(perps): potential rate limit on close positions cp-7.63.0 cp-7.64.0 7.62.2 fix(perps): potential rate limit on close positions cp-7.63.0 cp-7.64.0 cp-7.62.2 Jan 30, 2026
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.

@github-actions
Copy link
Copy Markdown
Contributor

🔍 Smart E2E Test Selection

  • Selected E2E tags: SmokeAccounts, SmokeConfirmationsRedesigned, SmokeIdentity, SmokeNetworkAbstractions, SmokeNetworkExpansion, SmokeTrade, SmokeWalletPlatform, SmokeCard, SmokeRewards, SmokePerps, SmokeRamps, SmokeMultiChainAPI, SmokePredictions, FlaskBuildTests
  • Selected Performance tags: @PerformanceAccountList, @PerformanceOnboarding, @PerformanceLogin, @PerformanceSwaps, @PerformanceLaunch, @PerformanceAssetLoading, @PerformancePredict, @PerformancePreps
  • Risk Level: high
  • AI Confidence: %
click to see 🤖 AI reasoning details

E2E Test Selection:
Fallback: AI analysis did not complete successfully. Running all tests.

Performance Test Selection:
Fallback: AI analysis did not complete successfully. Running all performance tests.

View GitHub Actions results

@aganglada aganglada enabled auto-merge January 30, 2026 16:24
@sonarqubecloud
Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

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

See analysis details on SonarQube Cloud

@aganglada aganglada added the skip-sonar-cloud Only used for bypassing sonar cloud when failures are not relevant to the changes. label Jan 30, 2026
@aganglada aganglada added this pull request to the merge queue Jan 30, 2026
Merged via the queue into main with commit 6f89dec Jan 30, 2026
177 of 182 checks passed
@aganglada aganglada deleted the fix/perps/skipcache-order branch January 30, 2026 17:43
@github-actions github-actions bot locked and limited conversation to collaborators Jan 30, 2026
@metamaskbot metamaskbot added the release-7.65.0 Issue or pull request that will be included in release 7.65.0 label Jan 30, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

release-7.65.0 Issue or pull request that will be included in release 7.65.0 size-S 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.

4 participants