@kinetiq-research/markets-assets
Version:
Asset metadata (descriptions, oracle references) for Kinetiq markets
43 lines (39 loc) • 1.08 kB
text/typescript
// Hyperliquid's concise-annotations endpoint returns a free-form string for
// each universe item's `category`. Normalize observed values to a narrow
// union. Unknown values fall back to `'stock'` so new listings still render
// somewhere sensible. Main Hyperliquid perps are not annotated and use the
// `isMainHyperliquid` flag to short-circuit to `'crypto'`.
export type AssetCategory =
| 'commodity'
| 'crypto'
| 'currency'
| 'index'
| 'stock'
const ALIASES: Record<string, AssetCategory> = {
commodities: 'commodity',
commodity: 'commodity',
crypto: 'crypto',
currencies: 'currency',
currency: 'currency',
equities: 'stock',
equity: 'stock',
forex: 'currency',
fx: 'currency',
index: 'index',
indexes: 'index',
indices: 'index',
stock: 'stock',
stocks: 'stock',
}
export const normalizeAssetCategory = ({
isMainHyperliquid = false,
raw,
}: {
isMainHyperliquid?: boolean
raw: string | undefined
}): AssetCategory => {
if (isMainHyperliquid) {
return 'crypto'
}
return ALIASES[raw?.toLowerCase() ?? ''] ?? 'stock'
}