get_orderbook_trades
Retrieve recent filled orders from the Polymarket orderbook subgraph, with optional filters by maker or taker address.
Instructions
Get recent order fills from the Orderbook subgraph
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| first | No | Number of trades to return | |
| maker | No | Optional: filter by maker address | |
| taker | No | Optional: filter by taker address |
Implementation Reference
- src/index.ts:349-387 (registration)Registration of the 'get_orderbook_trades' MCP tool with input schema using Zod validation. Defines the tool name, description, input parameters (first, maker, taker), and handler function.
server.registerTool( "get_orderbook_trades", { description: "Get recent order fills from the Orderbook subgraph", inputSchema: { first: z.number().min(1).max(100).default(20).describe("Number of trades to return"), maker: z.string().optional().describe("Optional: filter by maker address"), taker: z.string().optional().describe("Optional: filter by taker address"), }, }, async ({ first, maker, taker }) => { try { const filters: string[] = []; if (maker) filters.push(`maker: "${maker.toLowerCase()}"`); if (taker) filters.push(`taker: "${taker.toLowerCase()}"`); const where = filters.length > 0 ? `, where: { ${filters.join(", ")} }` : ""; const query = `{ orderFilledEvents(first: ${first}, orderBy: timestamp, orderDirection: desc${where}) { id maker taker makerAssetId takerAssetId makerAmountFilled takerAmountFilled fee price side timestamp } }`; const data = await querySubgraph(SUBGRAPHS.orderbook.ipfsHash, query); return textResult(data); } catch (error) { return errorResult(error); } } ); - src/index.ts:359-387 (handler)Handler function for get_orderbook_trades. Constructs a GraphQL query to fetch orderFilledEvents from the Orderbook subgraph, with optional maker/taker filters, and returns the results. The entire tool registration (lines 349-387) is both the registration and the handler inline.
async ({ first, maker, taker }) => { try { const filters: string[] = []; if (maker) filters.push(`maker: "${maker.toLowerCase()}"`); if (taker) filters.push(`taker: "${taker.toLowerCase()}"`); const where = filters.length > 0 ? `, where: { ${filters.join(", ")} }` : ""; const query = `{ orderFilledEvents(first: ${first}, orderBy: timestamp, orderDirection: desc${where}) { id maker taker makerAssetId takerAssetId makerAmountFilled takerAmountFilled fee price side timestamp } }`; const data = await querySubgraph(SUBGRAPHS.orderbook.ipfsHash, query); return textResult(data); } catch (error) { return errorResult(error); } } );