get_top_traders
Identify top-performing traders by analyzing volume, trade frequency, or profit/loss metrics across market types to inform trading strategies.
Instructions
Get top traders ranked by volume, trade count, or PnL. Queries both subgraphs and merges rankings.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| orderBy | No | totalVolumeUSD | |
| first | No | ||
| marketType | No | Filter by market type or combine both | all |
Implementation Reference
- mcp-server/src/index.ts:346-388 (handler)The handler for 'get_top_traders' retrieves data from subgraphs and merges results based on the provided marketType.
async ({ orderBy, first, marketType }) => { try { const userQuery = `{ users(first: ${first * 2}, orderBy: ${orderBy}, orderDirection: desc, where: { tradesCount_gt: "0" }) { id tradesCount totalVolumeUSD totalFeesUSD realizedPnlUSD firstTradeAt lastTradeAt } }`; if (marketType === "simple") { const data = await querySimple(userQuery); return textResult({ marketType, traders: (data.users || []).slice(0, first) }); } if (marketType === "negrisk") { const data = await queryNegRisk(userQuery); return textResult({ marketType, traders: (data.users || []).slice(0, first) }); } // Merge both const { simple, negrisk } = await queryBoth(userQuery, userQuery); const merged = new Map<string, any>(); for (const u of [...(simple.users || []), ...(negrisk.users || [])]) { const existing = merged.get(u.id); if (existing) { existing.tradesCount = parseInt(existing.tradesCount) + parseInt(u.tradesCount); existing.totalVolumeUSD = parseFloat(existing.totalVolumeUSD) + parseFloat(u.totalVolumeUSD); existing.totalFeesUSD = parseFloat(existing.totalFeesUSD) + parseFloat(u.totalFeesUSD); existing.realizedPnlUSD = parseFloat(existing.realizedPnlUSD) + parseFloat(u.realizedPnlUSD); } else { merged.set(u.id, { ...u, tradesCount: parseInt(u.tradesCount), totalVolumeUSD: parseFloat(u.totalVolumeUSD), totalFeesUSD: parseFloat(u.totalFeesUSD), realizedPnlUSD: parseFloat(u.realizedPnlUSD), }); } } - mcp-server/src/index.ts:330-345 (registration)Tool registration and input schema definition for 'get_top_traders'.
server.registerTool( "get_top_traders", { description: "Get top traders ranked by volume, trade count, or PnL. Queries both subgraphs and merges rankings.", inputSchema: { orderBy: z .enum(["totalVolumeUSD", "tradesCount", "totalFeesUSD"]) .default("totalVolumeUSD"), first: z.number().default(20), marketType: z .enum(["simple", "negrisk", "all"]) .default("all") .describe("Filter by market type or combine both"), }, },