get_trader_positions
Retrieve a trader's current positions, balances, and PnL across market types using their wallet address.
Instructions
Get a trader's current positions across both market types with balances and PnL.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| address | Yes | Trader wallet address |
Implementation Reference
- mcp-server/src/index.ts:467-514 (handler)The tool 'get_trader_positions' is registered and implemented directly in mcp-server/src/index.ts. It handles querying both 'simple' and 'negrisk' market types, hydrates condition names, and returns the positions.
server.registerTool( "get_trader_positions", { description: "Get a trader's current positions across both market types with balances and PnL.", inputSchema: { address: z.string().describe("Trader wallet address"), }, }, async ({ address }) => { try { const addr = address.toLowerCase(); const posQuery = `{ userPositions(where: { user: "${addr}", balance_gt: "0" }, first: 100) { id tokenId balance netCostUSD realizedPnlUSD lastUpdated condition { id resolved payoutNumerators } } }`; const { simple, negrisk } = await queryBoth(posQuery, posQuery); const allPositions = [ ...(simple.userPositions || []).map((p: any) => ({ ...p, marketType: "simple" })), ...(negrisk.userPositions || []).map((p: any) => ({ ...p, marketType: "negrisk" })), ]; // Hydrate condition names const conditionIds = [ ...new Set(allPositions.map((p: any) => p.condition?.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 = allPositions.map((p: any) => ({ ...p, marketName: names.get(p.condition?.id) || p.condition?.id || "unknown", })); return textResult({ address: addr, positionCount: enriched.length, positions: enriched }); } catch (e) { return errorResult(e); } } );