chore: use Terminal API price/trend data instead of HyperLiquid - #9808
Open
juanmigdr wants to merge 6 commits into
Open
chore: use Terminal API price/trend data instead of HyperLiquid#9808juanmigdr wants to merge 6 commits into
juanmigdr wants to merge 6 commits into
Conversation
…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
Open
10 tasks
juanmigdr
temporarily deployed
to
default-branch
August 7, 2026 20:00 — with
GitHub Actions
Inactive
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.
…-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.
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 0ed8a7a. Configure here.
…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
enabled auto-merge
August 10, 2026 12:06
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.

Summary
TerminalMarketServicealready fetches a Terminal API response that includes liveprice,change24h,changePercent24h,funding,volume24h,openInterest, and an hourlytrendseries per market - but it only ever extracted the taxonomy fields (name, keywords, tags, category).MarketDataServicethen 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, buildsPerpsMarketData[]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.categoryfield, notcategories(array) ormarketType. The struct was validating against field names the API never sends, soPerpsMarketData.marketTypesilently stayedundefinedfor 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.tsandMarketDataService.test.tsupdated with new fixtures/assertions, plus new tests for the price/trend extraction, the price"0"edge case, and rejecting malformedtrendpayloadsperps-controllerpackage test suite passestsc --noEmitandeslintclean on touched filesNote
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
useTerminalApiis on,getMarketDataWithPricescan buildPerpsMarketDatafrom 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.PerpsControllerpassesisMarketAllowedinto that path so HIP-3 allowlist/blocklist rules still apply when the provider is bypassed.TerminalMarketServicenow validates and copies live fields from the API, maps singularcategory→marketType(fixing undefined categories and broken filtering / “new market” badges), and acceptsnullon those numeric/trend fields so items are not dropped.categoriesis removed fromTerminalAssetMetadata/PerpsMarketDataenrichment.Shared
formatMarketPriceFieldsandderiveHip3MarketFieldsinmarketDataTransformkeep 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.