get_last_trade
Get the last trade price for a Polymarket outcome token by providing its CLOB token ID.
Instructions
Get the last trade price for a Polymarket outcome token from the CLOB.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| tokenId | Yes | CLOB token ID |
Implementation Reference
- src/index.ts:1246-1265 (registration)Registration of the 'get_last_trade' MCP tool. Defines input schema (tokenId) and handler that calls getClobLastTradePrice.
// Tool 29: get_last_trade // --------------------------------------------------------------------------- server.registerTool( "get_last_trade", { description: "Get the last trade price for a Polymarket outcome token from the CLOB.", inputSchema: { tokenId: z.string().describe("CLOB token ID"), }, }, async ({ tokenId }) => { try { const result = await getClobLastTradePrice(tokenId); return textResult({ tokenId, ...result }); } catch (error) { return errorResult(error); } } ); - src/polymarketApi.ts:193-199 (handler)Actual handler/helper function that fetches the last trade price from the CLOB API endpoint /last-trade-price.
export async function getClobLastTradePrice( tokenId: string ): Promise<{ price: string }> { return fetchJson<{ price: string }>( `${CLOB_BASE}/last-trade-price?token_id=${encodeURIComponent(tokenId)}` ); } - src/polymarketApi.ts:19-31 (helper)Generic helper that performs the HTTP fetch and JSON parsing for all CLOB API calls including getClobLastTradePrice.
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:6-7 (helper)Base URL constant for the CLOB API, used by getClobLastTradePrice to construct the endpoint URL.
const CLOB_BASE = "https://clob.polymarket.com"; - src/index.ts:10-24 (registration)Import of getClobLastTradePrice from polymarketApi, used in the get_last_trade tool handler.
import { searchMarkets, getMarketBySlug, getMarketByConditionId, listEvents, getEvent, getClobPrice, getClobPricesBatch, getClobMidpoint, getClobSpread, getClobOrderBook, getClobLastTradePrice, getClobPriceHistory, getClobMarket, } from "./polymarketApi.js";