fix: cp-7.59.0 market list open interest sort #22294
Merged
+220
−16
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.



Description
Summary
Fixes incorrect open interest calculation in the market list. Open interest was showing values in thousands instead of billions because the calculation wasn't converting raw contract units to USD by multiplying by the current price.
Root Cause
The transformMarketData() function used by the market list was parsing raw open interest values directly:
// BEFORE (incorrect)const openInterest = assetCtx?.openInterest ? parseFloat(assetCtx.openInterest) : NaN;
This treated open interest as USD when it's actually in contract units. For example, BTC with 1M open interest contracts at $50K should be $50B, but was showing as $1M.
Solution
Created a centralized calculateOpenInterestUSD() utility function that properly converts contract units to USD by multiplying by the current price:
// AFTER (correct)const openInterest = calculateOpenInterestUSD( assetCtx?.openInterest, effectiveCurrentPrice,);
This utility is now used consistently in:
transformMarketData() - Initial REST API data transformation (market list)
HyperLiquidSubscriptionService - WebSocket real-time updates (2 locations)
Known Discrepancy (Not Addressed in This PR)
There are two separate data sources for market data:
Market List: Uses REST API snapshot via getMarketDataWithPrices()
Data source: allMids prices from REST API
Update frequency: Cached, refreshes periodically or on pull-to-refresh
Use case: Browsing markets
Market Statistics Card: Uses real-time WebSocket via subscribeToPrices()
Data source: midPx || markPx from WebSocket
Update frequency: Real-time, updates every ~1-2 seconds
Use case: Viewing specific market details
Impact: While both now use the same calculation logic (calculateOpenInterestUSD), the market list shows a snapshot while the statistics card shows live real-time values. This is by design to prevent scroll jumping and excessive re-renders in the list view. Users can pull-to-refresh to update the market list.
Changes Made
Created utility function: calculateOpenInterestUSD() in marketDataTransform.ts
Updated market list: Uses utility in transformMarketData()
Updated WebSocket service: Uses utility in HyperLiquidSubscriptionService (2 locations)
Changelog
CHANGELOG entry: null
Related issues
Fixes: https://consensyssoftware.atlassian.net/browse/TAT-1972
Manual testing steps
Screenshots/Recordings
Before
After
Pre-merge author checklist
Pre-merge reviewer checklist
Note
Centralizes open interest USD calculation and uses it in REST transform and WebSocket subscriptions, updating displays and adding unit tests.
calculateOpenInterestUSDinapp/components/UI/Perps/utils/marketDataTransform.tsand use it intransformMarketData()to convert contract units × price to USD.app/components/UI/Perps/services/HyperLiquidSubscriptionService.tsto computeopenInterestviacalculateOpenInterestUSDin bothactiveAssetCtxandassetCtxshandlers.app/components/UI/Perps/utils/marketDataTransform.test.tswith comprehensive tests forcalculateOpenInterestUSDand adjust expectations (e.g., BTCopenInterestto$52.00B).Written by Cursor Bugbot for commit f48648e. This will update automatically on new commits. Configure here.