get_price_history
Retrieve historical price points for a Polymarket outcome token to analyze trends and create charts. Supports customizable intervals and data point counts.
Instructions
Get historical price data for a Polymarket outcome token. Returns time-series price points for charting and trend analysis.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| tokenId | Yes | CLOB token ID | |
| interval | No | Time interval: 1m, 5m, 1h, 6h, 1d, 1w, or max | 1d |
| fidelity | No | Number of data points to return (1-500) |
Implementation Reference
- src/index.ts:1206-1243 (registration)Tool 28 'get_price_history' registration in the MCP server. Defined with inputSchema requiring tokenId, interval (1m/5m/1h/6h/1d/1w/max), and fidelity (1-500). Handler calls getClobPriceHistory() and transforms the response.
server.registerTool( "get_price_history", { description: "Get historical price data for a Polymarket outcome token. Returns time-series price points for charting and trend analysis.", inputSchema: { tokenId: z.string().describe("CLOB token ID"), interval: z .enum(["1m", "5m", "1h", "6h", "1d", "1w", "max"]) .default("1d") .describe("Time interval: 1m, 5m, 1h, 6h, 1d, 1w, or max"), fidelity: z .number() .min(1) .max(500) .default(60) .describe("Number of data points to return (1-500)"), }, }, async ({ tokenId, interval, fidelity }) => { try { const data = await getClobPriceHistory(tokenId, interval, fidelity); const history = (data.history ?? []).map((p) => ({ timestamp: p.t, date: new Date(p.t * 1000).toISOString(), price: p.p, })); return textResult({ tokenId, interval, pointCount: history.length, history, }); } catch (error) { return errorResult(error); } } ); - src/polymarketApi.ts:201-209 (handler)getClobPriceHistory() — the actual implementation function that calls the Polymarket CLOB API at /prices-history endpoint. Takes tokenId, interval, and fidelity; returns { history: Array<{ t: number, p: number }> }.
export async function getClobPriceHistory( tokenId: string, interval: string = "1d", fidelity: number = 60 ): Promise<{ history: Array<{ t: number; p: number }> }> { return fetchJson<{ history: Array<{ t: number; p: number }> }>( `${CLOB_BASE}/prices-history?market=${encodeURIComponent(tokenId)}&interval=${interval}&fidelity=${fidelity}` ); } - src/index.ts:1211-1224 (schema)Input schema for get_price_history: tokenId (string), interval (enum: 1m/5m/1h/6h/1d/1w/max, default 1d), fidelity (number 1-500, default 60).
inputSchema: { tokenId: z.string().describe("CLOB token ID"), interval: z .enum(["1m", "5m", "1h", "6h", "1d", "1w", "max"]) .default("1d") .describe("Time interval: 1m, 5m, 1h, 6h, 1d, 1w, or max"), fidelity: z .number() .min(1) .max(500) .default(60) .describe("Number of data points to return (1-500)"), }, }, - src/polymarketApi.ts:19-31 (helper)fetchJson<T>() — generic HTTP helper used by getClobPriceHistory to make requests to the CLOB API with JSON parsing and error handling.
async function fetchJson<T>(url: string): Promise<T> { const response = await fetch(url, { headers: { Accept: "application/json" }, }); if (!response.ok) { throw new PolymarketApiError( `HTTP ${response.status}: ${response.statusText}`, response.status, url ); } return response.json() as Promise<T>; }