Skip to content

fix(perps): use live price for reverse position orders#8481

Closed
geositta wants to merge 3 commits intomainfrom
feat/perps/reverse-position-live-price-sync
Closed

fix(perps): use live price for reverse position orders#8481
geositta wants to merge 3 commits intomainfrom
feat/perps/reverse-position-live-price-sync

Conversation

@geositta
Copy link
Copy Markdown

@geositta geositta commented Apr 16, 2026

Explanation

Sync the perps controller fix from mobile so reverse-position orders no longer use a stale entry price during flip order placement.

The issue was in TradingService.flipPosition(): it passed position.entryPrice as currentPrice for the market flip order. That value could be stale relative to the live market, which meant provider side validation and IOC pricing could use the wrong price and cause reverse position failures. This change removes that stale price from the flip order params so the provider uses live market pricing instead, and it updates the order value analytics fallback accordingly.

This PR also updates the perps controller changelog entry and sync state as part of the standard mobile-to-core sync flow.

References

Checklist

  • I've updated the test suite for new or updated code as appropriate
  • I've updated documentation (JSDoc, Markdown, etc.) for new or updated code as appropriate
  • I've communicated my changes to consumers by updating changelogs for packages I've changed
  • I've introduced breaking changes in this PR and have prepared draft pull requests for clients and consumer packages to resolve them

Note

Medium Risk
Changes perps position-flip order submission by removing fee/balance prechecks and no longer sending a potentially stale currentPrice, which could affect provider-side validation and analytics values if assumptions differ.

Overview
Fixes reverse-position (flip) market orders by stopping flipPosition() from passing position.entryPrice as currentPrice, forcing providers to validate/price against live market data.

Removes the flip fee/balance prevalidation based on ESTIMATED_FEE_RATE, and updates flip analytics ORDER_VALUE to use the executed averagePrice (falling back to entry price) instead. Changelog and .sync-state.json are updated to reflect the synced fix.

Reviewed by Cursor Bugbot for commit a12f5dd. Bugbot is set up for automated code reviews on this repo. Configure here.

@geositta geositta requested review from a team as code owners April 16, 2026 06:34
Comment thread packages/perps-controller/src/PerpsController.ts Outdated
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.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit f681e4a. Configure here.

PERPS_EVENT_PROPERTY,
PERPS_EVENT_VALUE,
} from '../constants/eventNames';
import { ESTIMATED_FEE_RATE } from '../constants/hyperLiquidConfig';
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Orphaned constant after removing its only usage

Low Severity

The ESTIMATED_FEE_RATE import was removed from TradingService.ts along with the fee validation block, but the constant itself is still exported from hyperLiquidConfig.ts. A repo-wide search confirms it has zero remaining references — it's now dead code introduced by this change.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit f681e4a. Configure here.

@geositta geositta force-pushed the feat/perps/reverse-position-live-price-sync branch from f681e4a to a12f5dd Compare April 17, 2026 14:22
@geositta
Copy link
Copy Markdown
Author

core/main already contains these perps-controller changes, so this PR is superseded. The reverse position live price fix and the later follow-up sync changes are now present on main.

@geositta geositta closed this Apr 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants