get_market_positions
Query largest token holders and their profit and loss for a Polymarket outcome token, sortable by realized or unrealized PnL or value bought.
Instructions
Get the top positions for a specific market token from the Beefy P&L subgraph. Shows who holds the largest positions and their P&L.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| tokenId | Yes | The outcome token ID — same value as clobTokenIds from search_markets/get_market_info, token_id from get_clob_market, or makerAssetId/takerAssetId from get_orderbook_trades | |
| first | No | Number of positions to return | |
| orderBy | No | Field to sort by | valueBought |
Implementation Reference
- src/index.ts:546-588 (registration)Registration of the 'get_market_positions' MCP tool. Defines the tool name, description, input schema (tokenId, first, orderBy), and the handler function that queries the Beefy P&L subgraph for top positions by market token.
// Tool 12: get_market_positions // --------------------------------------------------------------------------- server.registerTool( "get_market_positions", { description: "Get the top positions for a specific market token from the Beefy P&L subgraph. Shows who holds the largest positions and their P&L.", inputSchema: { tokenId: z .string() .describe( "The outcome token ID — same value as clobTokenIds from search_markets/get_market_info, token_id from get_clob_market, or makerAssetId/takerAssetId from get_orderbook_trades" ), first: z.number().min(1).max(100).default(20).describe("Number of positions to return"), orderBy: z .enum(["realizedPnl", "unrealizedPnl", "valueBought"]) .default("valueBought") .describe("Field to sort by"), }, }, async ({ tokenId, first, orderBy }) => { try { const query = `{ marketPositions( first: ${first}, orderBy: ${orderBy}, orderDirection: desc, where: { id_contains: "${tokenId}" } ) { id realizedPnl unrealizedPnl valueBought valueSold } }`; const data = await querySubgraph(SUBGRAPHS.beefy_pnl.ipfsHash, query); return textResult(data); } catch (error) { return errorResult(error); } } ); - src/index.ts:566-588 (handler)Handler function for get_market_positions. Takes tokenId, first (default 20), and orderBy (realizedPnl/unrealizedPnl/valueBought, default valueBought). Queries the Beefy P&L subgraph for marketPositions filtered by id_contains tokenId, returning id, realizedPnl, unrealizedPnl, valueBought, valueSold.
async ({ tokenId, first, orderBy }) => { try { const query = `{ marketPositions( first: ${first}, orderBy: ${orderBy}, orderDirection: desc, where: { id_contains: "${tokenId}" } ) { id realizedPnl unrealizedPnl valueBought valueSold } }`; const data = await querySubgraph(SUBGRAPHS.beefy_pnl.ipfsHash, query); return textResult(data); } catch (error) { return errorResult(error); } } ); - src/index.ts:553-565 (schema)Input schema for get_market_positions. Defines tokenId (string, outcome token ID), first (number 1-100, default 20), and orderBy (enum of realizedPnl, unrealizedPnl, valueBought, default valueBought).
inputSchema: { tokenId: z .string() .describe( "The outcome token ID — same value as clobTokenIds from search_markets/get_market_info, token_id from get_clob_market, or makerAssetId/takerAssetId from get_orderbook_trades" ), first: z.number().min(1).max(100).default(20).describe("Number of positions to return"), orderBy: z .enum(["realizedPnl", "unrealizedPnl", "valueBought"]) .default("valueBought") .describe("Field to sort by"), }, },