get_live_orderbook
Retrieve the real-time order book for any Polymarket outcome token, displaying all resting bids and asks with prices and sizes.
Instructions
Get the full real-time order book (bids and asks) for a Polymarket outcome token from the CLOB. Shows all resting limit orders with prices and sizes.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| tokenId | Yes | CLOB token ID |
Implementation Reference
- src/index.ts:1177-1201 (registration)Registration of the 'get_live_orderbook' MCP tool. Defines input schema (tokenId), description, and handler that calls getClobOrderBook and formats the response.
server.registerTool( "get_live_orderbook", { description: "Get the full real-time order book (bids and asks) for a Polymarket outcome token from the CLOB. Shows all resting limit orders with prices and sizes.", inputSchema: { tokenId: z.string().describe("CLOB token ID"), }, }, async ({ tokenId }) => { try { const book = await getClobOrderBook(tokenId); return textResult({ tokenId, bidCount: book.bids?.length ?? 0, askCount: book.asks?.length ?? 0, bids: book.bids, asks: book.asks, timestamp: book.timestamp, }); } catch (error) { return errorResult(error); } } ); - src/polymarketApi.ts:187-191 (handler)The actual implementation of the order book fetching logic. Calls the CLOB API endpoint /book with the token_id parameter and returns a typed ClobOrderBook response.
export async function getClobOrderBook(tokenId: string): Promise<ClobOrderBook> { return fetchJson<ClobOrderBook>( `${CLOB_BASE}/book?token_id=${encodeURIComponent(tokenId)}` ); } - src/polymarketApi.ts:126-133 (schema)Type definition for the CLOB order book response. Defines the shape: market, asset_id, bids/asks arrays, hash, and timestamp.
export interface ClobOrderBook { market: string; asset_id: string; bids: ClobPrice[]; asks: ClobPrice[]; hash: string; timestamp: string; } - src/polymarketApi.ts:121-124 (schema)Type definition for individual bid/ask price levels in the order book, containing price and size fields.
export interface ClobPrice { price: string; size: string; } - src/polymarketApi.ts:19-31 (helper)Generic HTTP fetch helper used by getClobOrderBook to make the API call and parse JSON response.
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>; }