feat(perps): extend market categories#8892
Conversation
abretonc7s
left a comment
There was a problem hiding this comment.
Category filtering currently accepts valid inputs that return empty or incomplete results. Watchlist filtering needs implementation or removal from the accepted API, and explicit crypto categorization should be honored.
abretonc7s
left a comment
There was a problem hiding this comment.
One more API-surface issue: GetMarketsParams now exposes filters that getMarkets does not apply.
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 46c4f27. Configure here.
abretonc7s
left a comment
There was a problem hiding this comment.
One TypeScript API compatibility issue remains.

Explanation
Implements TAT-3182 — expands market categories in
@metamask/perps-controllerwith a new enum, static array, and filtering/sorting support ongetMarketDataWithPrices.What changed
New types and constants
MarketCategoryenum (crypto,stock,pre-ipo,index,etf,commodity,forex) — replaces ad-hoc string literals inHIP3_ASSET_MARKET_TYPESMarketTypetype alias kept for backward compatibilityMARKET_CATEGORIESconstant (readonly MarketTypeFilter[]) — 7 ordered category pills, enforced viasatisfies; does not include'all'/'new'sentinels (those are separate UI controls)SortFieldandSortDirectionmoved totypes/index.ts(re-exported fromutils/sortMarkets) to avoid circular importsNew controller method
getMarketCategories()— returnsMARKET_CATEGORIESso clients can enumerate pills at runtime without hardcoding the listExtended params
GetMarketsParamsgains four optional fields:categories,sortBy,direction,limitPerpsProvider.getMarketDataWithPrices()accepts the same fields viaPick<GetMarketsParams, ...>Filtering / sorting / pagination (in
MarketDataService, notPerpsController)matchesCategory()— pure function mappingMarketTypeFilter | 'watchlist'to aPerpsMarketDatapredicateapplyMarketFilters()— applies category filter (OR logic) → sort → slice in orderMarketDataService.getMarketDataWithPrices()— new service method with tracing and error handling that fetches from the provider then applies filtersBreaking change
'equity'market type replaced by'stock','pre-ipo','index','etf'References
Checklist
Note
Medium Risk
Breaking
MarketTypevalues require consumer updates; market-list filtering changes behavior for any code that assumed unfiltered provider output fromgetMarketDataWithPrices.Overview
This PR extends HIP-3 market taxonomy and list APIs in
@metamask/perps-controllerso clients can render category pills and fetch filtered market lists without duplicating logic.MarketCategoryreplaces loose'equity'strings withstock,pre-ipo,index,etf, plus existingcommodity,forex, andcrypto.HIP3_ASSET_MARKET_TYPESis updated accordingly (many new xyz symbols; indices/ETFs split out from the old equity bucket).MARKET_CATEGORIESexposes a fixed order of seven UI pill keys, andgetMarketCategories()(new messenger action) returns that list.getMarketDataWithPricesnow acceptsGetMarketDataWithPricesParams(categories,sortBy,direction,limit,excludeSymbols,standalone) and routes throughMarketDataService, which fetches from the provider then appliesmatchesCategory/applyMarketFilters(OR across categories, then exclude, sort, slice).SortField/SortDirectionmove to shared types and are re-exported from the package entry.Breaking: consumers comparing
marketType === 'equity'must switch to the granular types. Changelog and tests cover categories, filtering, sorting, limits, and config classification.Reviewed by Cursor Bugbot for commit 4a7057c. Bugbot is set up for automated code reviews on this repo. Configure here.