get_trader_trades
Retrieve a trader's recent trades across markets with enriched market names, filtering by trade role and wallet address.
Instructions
Get a trader's recent trades across both market types, enriched with market names.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| address | Yes | Trader wallet address | |
| first | No | ||
| role | No | Filter by role in trade | both |
Implementation Reference
- mcp-server/src/index.ts:418-457 (handler)The handler function for 'get_trader_trades' that queries both 'simple' and 'negrisk' markets, hydrates market names, and returns enriched trade data.
async ({ address, first, role }) => { try { const addr = address.toLowerCase(); let where = ""; if (role === "maker") where = `maker: "${addr}"`; else if (role === "taker") where = `taker: "${addr}"`; else where = `or: [{maker: "${addr}"}, {taker: "${addr}"}]`; const tradesQuery = `{ trades(first: ${first}, orderBy: timestamp, orderDirection: desc, where: { ${where} }) { id market { id } type maker taker amountUSD feeUSD price venue timestamp txHash } }`; const negriskTradesQuery = tradesQuery.replace("market { id }", "market { id }"); const { simple, negrisk } = await queryBoth(tradesQuery, negriskTradesQuery); const allTrades = [ ...(simple.trades || []).map((t: any) => ({ ...t, marketType: "simple" })), ...(negrisk.trades || []).map((t: any) => ({ ...t, marketType: "negrisk" })), ] .sort((a, b) => Number(b.timestamp) - Number(a.timestamp)) .slice(0, first); // Hydrate market names const conditionIds = [...new Set(allTrades.map((t: any) => t.market?.id).filter(Boolean))]; const names = new Map<string, string>(); await Promise.all( conditionIds.map(async (id: string) => { names.set(id, await hydrateName(id)); }) ); const enriched = allTrades.map((t: any) => ({ ...t, marketName: names.get(t.market?.id) || t.market?.id || "unknown", })); return textResult({ address: addr, trades: enriched }); - mcp-server/src/index.ts:404-417 (registration)Tool registration for 'get_trader_trades' including input schema definition.
server.registerTool( "get_trader_trades", { description: "Get a trader's recent trades across both market types, enriched with market names.", inputSchema: { address: z.string().describe("Trader wallet address"), first: z.number().default(20), role: z .enum(["maker", "taker", "both"]) .default("both") .describe("Filter by role in trade"), }, },