get_live_spread
Retrieve real-time bid and ask prices for a Polymarket outcome token to calculate the spread, enabling assessment of market liquidity and trading costs.
Instructions
Get the real-time bid-ask spread for a Polymarket outcome token. Returns best bid, best ask, and spread. Useful for assessing market liquidity and trading costs.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| tokenId | Yes | CLOB token ID |
Implementation Reference
- src/index.ts:1152-1172 (registration)Registration of the 'get_live_spread' tool using server.registerTool. Defines the input schema (tokenId: string) and calls getClobSpread + getClobMidpoint helper functions.
server.registerTool( "get_live_spread", { description: "Get the real-time bid-ask spread for a Polymarket outcome token. Returns best bid, best ask, and spread. Useful for assessing market liquidity and trading costs.", inputSchema: { tokenId: z.string().describe("CLOB token ID"), }, }, async ({ tokenId }) => { try { const [spread, midpoint] = await Promise.all([ getClobSpread(tokenId), getClobMidpoint(tokenId), ]); return textResult({ tokenId, ...spread, midpoint: midpoint.mid }); } catch (error) { return errorResult(error); } } ); - src/index.ts:1161-1171 (handler)Handler function for get_live_spread. Calls getClobSpread(tokenId) and getClobMidpoint(tokenId) in parallel, then returns the spread, bid, ask, and midpoint.
async ({ tokenId }) => { try { const [spread, midpoint] = await Promise.all([ getClobSpread(tokenId), getClobMidpoint(tokenId), ]); return textResult({ tokenId, ...spread, midpoint: midpoint.mid }); } catch (error) { return errorResult(error); } } - src/polymarketApi.ts:179-185 (helper)The getClobSpread helper function that fetches the bid-ask spread from the CLOB API at /spread?token_id={tokenId}. Returns { spread, bid, ask }.
export async function getClobSpread( tokenId: string ): Promise<{ spread: string; bid: string; ask: string }> { return fetchJson<{ spread: string; bid: string; ask: string }>( `${CLOB_BASE}/spread?token_id=${encodeURIComponent(tokenId)}` ); } - src/polymarketApi.ts:173-177 (helper)The getClobMidpoint helper function that fetches the midpoint price from the CLOB API at /midpoint?token_id={tokenId}. Returns { mid }.
export async function getClobMidpoint(tokenId: string): Promise<{ mid: string }> { return fetchJson<{ mid: string }>( `${CLOB_BASE}/midpoint?token_id=${encodeURIComponent(tokenId)}` ); } - src/index.ts:1157-1159 (schema)Input schema for get_live_spread tool: a single required string parameter 'tokenId' representing the CLOB token ID.
inputSchema: { tokenId: z.string().describe("CLOB token ID"), },