list_markets
List all prediction markets with their current prices on Hyperliquid.
Instructions
List all prediction markets with current prices
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- mcp-server.ts:81-125 (handler)The handler function for the 'list_markets' tool. It fetches outcome metadata (questions + outcomes) and all mid prices from the Hyperliquid API, groups outcomes by their parent question, and returns a formatted text listing all prediction markets with current prices for each side.
// --- list_markets --- server.tool( 'list_markets', 'List all prediction markets with current prices', {}, async () => { const [meta, mids] = await Promise.all([ hlInfo<OutcomeMeta>({ type: 'outcomeMeta' }), hlInfo<Record<string, string>>({ type: 'allMids' }), ]); const questionMap = new Map<number, QuestionRaw>(); for (const q of meta.questions) { questionMap.set(q.question, q); } const lines: string[] = []; // Group outcomes by question const grouped = new Map<number | null, OutcomeRaw[]>(); for (const o of meta.outcomes) { const qId = [...questionMap.entries()].find(([, q]) => q.namedOutcomes.includes(o.outcome) )?.[0] ?? null; if (!grouped.has(qId)) grouped.set(qId, []); grouped.get(qId)!.push(o); } for (const [qId, outcomes] of grouped) { const q = qId !== null ? questionMap.get(qId) : null; if (q) lines.push(`\n## ${q.name}`); for (const o of outcomes) { const sides = o.sideSpecs.map((s, i) => { const coin = outcomeToCoin(o.outcome, i); const mid = mids[coin] ? (parseFloat(mids[coin]) * 100).toFixed(1) + '%' : '?'; return `${s.name}: ${mid}`; }); const label = q ? ` [${o.outcome}] ${o.name}` : `\n[${o.outcome}] ${o.name}`; lines.push(`${label} — ${sides.join(' | ')}`); } } return { content: [{ type: 'text', text: lines.join('\n') }] }; }, ); - mcp-server.ts:82-83 (registration)Registration of the 'list_markets' tool using the MCP server.tool() method with an empty schema (no input parameters).
server.tool( 'list_markets', - mcp-server.ts:63-65 (helper)Helper function outcomeToCoin, used to convert an outcome ID and side index into a coin identifier string (e.g., '#90') for fetching mid prices from the API.
function outcomeToCoin(outcomeId: number, side: number): string { return `#${10 * outcomeId + side}`; } - mcp-server.ts:31-45 (schema)Type definitions for OutcomeRaw, QuestionRaw, and OutcomeMeta, which define the shape of data used by the list_markets handler to structure markets and questions.
interface OutcomeRaw { outcome: number; name: string; description: string; sideSpecs: { name: string }[]; } interface QuestionRaw { question: number; name: string; description: string; fallbackOutcome: number; namedOutcomes: number[]; settledNamedOutcomes: number[]; } interface OutcomeMeta { outcomes: OutcomeRaw[]; questions: QuestionRaw[] }