get_live_prices
Fetch the current best buy or sell price for Polymarket outcome tokens using CLOB token IDs from search_markets or get_market_info.
Instructions
Get real-time CLOB prices for Polymarket outcome tokens. Returns the current best price for buying or selling. Token IDs come from: clobTokenIds in search_markets/get_market_info, or token_id in get_clob_market.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| tokenIds | Yes | Array of CLOB token IDs (get these from search_markets or get_market_info clobTokenIds field) | |
| side | No | Price side: buy or sell | buy |
Implementation Reference
- src/index.ts:1118-1147 (registration)Registration of the 'get_live_prices' tool. Calls getClobPrice for a single tokenId or getClobPricesBatch for multiple tokenIds from the polymarketApi module.
// --------------------------------------------------------------------------- // Tool 25: get_live_prices // --------------------------------------------------------------------------- server.registerTool( "get_live_prices", { description: "Get real-time CLOB prices for Polymarket outcome tokens. Returns the current best price for buying or selling. Token IDs come from: clobTokenIds in search_markets/get_market_info, or token_id in get_clob_market.", inputSchema: { tokenIds: z .array(z.string()) .min(1) .max(20) .describe("Array of CLOB token IDs (get these from search_markets or get_market_info clobTokenIds field)"), side: z.enum(["buy", "sell"]).default("buy").describe("Price side: buy or sell"), }, }, async ({ tokenIds, side }) => { try { if (tokenIds.length === 1) { const result = await getClobPrice(tokenIds[0], side); return textResult({ tokenId: tokenIds[0], side, ...result }); } const result = await getClobPricesBatch(tokenIds, side); return textResult({ side, prices: result }); } catch (error) { return errorResult(error); } } ); - src/polymarketApi.ts:156-163 (handler)Handler function getClobPrice: fetches a single CLOB price from the Polymarket CLOB API for a given token ID and side (buy/sell).
export async function getClobPrice( tokenId: string, side: "buy" | "sell" = "buy" ): Promise<{ price: string }> { return fetchJson<{ price: string }>( `${CLOB_BASE}/price?token_id=${encodeURIComponent(tokenId)}&side=${side}` ); } - src/polymarketApi.ts:165-171 (handler)Handler function getClobPricesBatch: fetches CLOB prices for multiple token IDs from the Polymarket CLOB API batch endpoint.
export async function getClobPricesBatch( tokenIds: string[], side: "buy" | "sell" = "buy" ): Promise<unknown> { const params = tokenIds.map((id) => `token_ids=${encodeURIComponent(id)}`).join("&"); return fetchJson<unknown>(`${CLOB_BASE}/prices?${params}&side=${side}`); } - src/polymarketApi.ts:19-31 (helper)Helper function fetchJson: generic JSON fetcher used by all CLOB API functions to make HTTP requests.
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>; } - src/polymarketApi.ts:121-124 (schema)Type definition for ClobPrice used in price responses.
export interface ClobPrice { price: string; size: string; }