Skip to content

chore: use Terminal API price/trend data instead of HyperLiquid - #9808

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

chore: use Terminal API price/trend data instead of HyperLiquid#9808
juanmigdr wants to merge 6 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-list data path (Terminal vs HyperLiquid) and market visibility rules when pricing is Terminal-sourced; behavior is well covered by new tests but affects discovery UI and category filtering.

Overview
When useTerminalApi is on, getMarketDataWithPrices can build PerpsMarketData from Terminal metadata (price, 24h change, funding, volume, OI, trend) and skip the HyperLiquid pricing call if at least one symbol has a usable price; otherwise it keeps the provider fetch + Terminal enrich path. PerpsController passes isMarketAllowed into that path so HIP-3 allowlist/blocklist rules still apply when the provider is bypassed.

TerminalMarketService now validates and copies live fields from the API, maps singular categorymarketType (fixing undefined categories and broken filtering / “new market” badges), and accepts null on those numeric/trend fields so items are not dropped. categories is removed from TerminalAssetMetadata / PerpsMarketData enrichment.

Shared formatMarketPriceFields and deriveHip3MarketFields in marketDataTransform keep Terminal and HyperLiquid formatting and HIP-3 flags aligned.

Reviewed by Cursor Bugbot for commit 113a9fa. 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
Comment thread packages/perps-controller/src/services/MarketDataService.ts
@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
@juanmigdr juanmigdr changed the title perf(perps-controller): use Terminal API price/trend data instead of HyperLiquid chore: use Terminal API price/trend data instead of HyperLiquid Aug 10, 2026
juanmigdr and others added 3 commits August 10, 2026 10:08
…-priced markets

Bugbot flagged that getMarketDataWithPrices' Terminal-sourced path
skipped the allowlist/blocklist filtering the HyperLiquid provider
applies, so blocklisted or non-allowlisted HIP-3 markets could show up
as tradeable even though order placement would still reject them.
getMarketDataWithPrices now takes the same isMarketAllowed callback
getMarkets already uses and filters Terminal-sourced markets with it
before deciding whether to skip the provider call.
…d and Terminal market builders

buildMarketsFromTerminalMetadata duplicated the same isNaN-guarded
price/change/volume/openInterest formatting ladder and HIP-3
marketSource/isHip3/isNewMarket derivation that transformMarketData
already had for the HyperLiquid path. Pulled both into shared
formatMarketPriceFields/deriveHip3MarketFields helpers in
marketDataTransform.ts so the two market sources can't drift apart,
and switched both call sites to use them. No behavior change.

@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 0ed8a7a. Configure here.

Comment thread packages/perps-controller/src/services/TerminalMarketService.ts Outdated
…ropping the item

Bugbot flagged that the newly declared price/change24h/changePercent24h/
funding/volume24h/openInterest/trend fields on TerminalPerpetualItemStruct
used optional(union(...)) without nullable, unlike sibling fields like
name/category/listedAt. A null value for any of them failed schema
validation and dropped the whole item, so markets with a null price
disappeared from both getMarkets and getMarketDataWithPrices instead of
just falling back on those fields. Wrapped them in nullable() and treat
null the same as undefined when extracting metadata.
@juanmigdr
juanmigdr enabled auto-merge August 10, 2026 12:06
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