fix: Perps/refresh hl live account cache#29217
Conversation
|
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. |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ 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 314faba. Configure here.
🔍 Smart E2E Test Selection⏭️ Smart E2E selection skipped - base branch is not main or a release branch (base: perps/fix-avail-balance-order-entry) All E2E tests pre-selected. |
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## perps/fix-avail-balance-order-entry #29217 +/- ##
======================================================================
Coverage ? 82.24%
======================================================================
Files ? 5101
Lines ? 134628
Branches ? 30242
======================================================================
Hits ? 110728
Misses ? 16375
Partials ? 7525 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
|
✅ E2E Fixture Validation — Schema is up to date |




Description
This PR builds on perps/fix-avail-balance-order-entry by fixing the remaining live-update gap for HyperLiquid availableToTradeBalance.
The parent branch corrected the balance math and UI usage, but after a successful trade or margin mutation the Perps home screen could still briefly show the right value and then get overwritten by stale streamed account data, because the live HyperLiquid account stream was still using cached spot state.
The solution is to refresh the existing streamed account path after successful trade mutations instead of adding new UI side refresh logic.
An optional refreshLiveAccountState() hook was added to the provider interface, implemented for HyperLiquid, and invoked by TradingService after successful order placement, close, flip, batch close, and margin updates.
On HyperLiquid, that forces a fresh spotClearinghouseState fetch and reuses the existing account aggregation/notification path, so subscribers receive an updated availableToTradeBalance from the live stream itself rather than a temporary one-off refresh.
Changelog
CHANGELOG entry:
Related issues
Fixes:
Manual testing steps
Screenshots/Recordings
Before
After
Pre-merge author checklist
Performance checks (if applicable)
trace()for usage andaddTokenfor an exampleFor performance guidelines and tooling, see the Performance Guide.
Pre-merge reviewer checklist
Note
Medium Risk
Touches post-trade state update paths and HyperLiquid subscription caching; mistakes could cause missed/extra refreshes or stale balances in the UI. Changes are guarded (optional provider method, no-op when unsubscribed) and covered by unit tests.
Overview
Fixes a stale-balance flicker by introducing optional
refreshLiveAccountState()onPerpsProvider, implemented inHyperLiquidProvider/HyperLiquidSubscriptionServiceto forcibly refetch spot state and re-notify existing account subscribers.TradingServicenow triggers this refresh (fire-and-forget with error logging) after successfulplaceOrder,cancelOrder/batch cancel,closePosition/batch close,updateMargin, andflipPosition, while keeping the behavior optional for providers that don’t implement it. Tests and mocks were updated to cover delegation viaAggregatedPerpsProviderand to ensure refreshes only occur on successful mutations and only when streamed account data is already active.Reviewed by Cursor Bugbot for commit d67be89. Bugbot is set up for automated code reviews on this repo. Configure here.