Skip to content

perf(perps-controller): use Terminal API price/trend data instead of HyperLiquid - #9808

Open
juanmigdr wants to merge 2 commits into
mainfrom
chore/remove-all-hyperliquid-api-calls
Open

perf(perps-controller): use Terminal API price/trend data instead of HyperLiquid#9808
juanmigdr wants to merge 2 commits into
mainfrom
chore/remove-all-hyperliquid-api-calls

Conversation

@juanmigdr

@juanmigdr juanmigdr commented Aug 7, 2026

Copy link
Copy Markdown
Member

Summary

TerminalMarketService already fetches a Terminal API response that includes live price, change24h, changePercent24h, funding, volume24h, openInterest, and an hourly trend series per market - but it only ever extracted the taxonomy fields (name, keywords, tags, category). MarketDataService then always fell back to HyperLiquid for pricing, even when the Terminal response it had just fetched already contained everything needed.

  • TerminalMarketService: declares the price/trend fields on the validation struct and copies them into the per-symbol metadata map alongside the existing taxonomy fields.
  • MarketDataService.getMarketDataWithPrices: when Terminal metadata has a usable price, builds PerpsMarketData[] directly from it (through the same injectable formatters used by the HyperLiquid path, so formatting is identical either way) and skips the HyperLiquid provider call. Falls back to the existing provider + enrich behavior otherwise.
  • Fixed a related bug found while testing this: the Terminal API sends a singular category field, not categories (array) or marketType. The struct was validating against field names the API never sends, so PerpsMarketData.marketType silently stayed undefined for Terminal-sourced markets, breaking category filtering and the "new market" badge for HIP-3 assets.

Companion mobile PR (updates the homepage Perpetuals section to consume this instead of subscribing to per-symbol candle streams): MetaMask/metamask-mobile#34511

Ticket: ASSETS-3858

Test plan

  • TerminalMarketService.test.ts and MarketDataService.test.ts updated with new fixtures/assertions, plus new tests for the price/trend extraction, the price "0" edge case, and rejecting malformed trend payloads
  • Full perps-controller package test suite passes
  • tsc --noEmit and eslint clean on touched files

Note

Medium Risk
Changes the primary market-overview data path when Terminal pricing is available; incorrect Terminal data or the all-symbols-dropped edge case could affect displayed markets, and removing PerpsMarketData.categories may break consumers that still read it.

Overview
When useTerminalApi is on and Terminal returns at least one market with a valid price, getMarketDataWithPrices now builds PerpsMarketData from Terminal metadata (same injectable formatters as the HyperLiquid path) and does not call the provider for pricing. Symbols without a usable price are omitted on that path; if nothing qualifies, behavior falls back to provider fetch plus Terminal enrichment.

TerminalMarketService now validates and copies live fields from the API (price, 24h change, funding, volume, open interest, trend, etc.) and maps the singular category string to marketType instead of the old categories / marketType fields that never matched the payload—restoring category filters and the HIP-3 “new market” badge. PerpsMarketData gains optional trend and drops the unused categories field from enrichment/types.

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

…HyperLiquid

TerminalMarketService already fetched a Terminal API response containing
live price, change, funding, volume, open interest, and hourly trend data
per market, but only the taxonomy fields were extracted. MarketDataService
then re-fetched pricing from HyperLiquid on every call, even when Terminal
had just returned it.

Now TerminalMarketService pulls the price/trend fields out of the validated
response, and MarketDataService builds market data straight from that when
it's usable, skipping the HyperLiquid call entirely. Falls back to the
existing provider + enrich behavior when Terminal has no price data.

Also fixes the Terminal category field being read as `categories`/
`marketType`, when the API actually sends singular `category` - it was
silently going unused, which broke market type filtering and the "new
market" badge for HIP-3 assets whenever the Terminal price path kicked in.

Companion mobile PR: MetaMask/metamask-mobile#34511

@cursor cursor Bot left a comment

Copy link
Copy Markdown

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 1155522. Configure here.

enriched = terminalMetadata
? this.#enrichWithTerminalMetadata(markets, terminalMetadata)
: markets;
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Terminal path skips market filters

High Severity

When Terminal metadata has any usable price, getMarketDataWithPrices returns Terminal-built markets and never calls the provider. That skips the eligibility rules HyperLiquidProvider.getMarketDataWithPrices applies via shouldIncludeMarket and #excludeNonUsdcCollateralResults (HIP-3 feature flag, allowlist/blocklist, USDC-only collateral). getMarkets already re-applies isMarketAllowed on its Terminal path for this reason, so blocklisted or non-USDC HIP-3 markets can surface as tradeable while order placement still rejects them.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 1155522. Configure here.

@juanmigdr juanmigdr added the area-performance Issues relating to slowness of app, cpu usage, and/or blank screens. label Aug 7, 2026
oxfmt flagged the Map<string, TerminalAssetMetadata> constructor call in
MarketDataService.test.ts from the earlier ZERO-price fixture addition.
Also adds the missing Unreleased changelog entries for the Terminal
pricing change and the category/marketType fix.
@juanmigdr
juanmigdr requested a review from a team as a code owner August 7, 2026 20:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-performance Issues relating to slowness of app, cpu usage, and/or blank screens.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant