config.history
Retrieve past copy trades from the database with optional filters by trader address or status. Get trade details including entry price, P&L, and market info. Pro feature.
Instructions
Retrieve past copy trades from the database with optional filters by trader address or status. Returns trade details including entry price, P&L, and market info. Pro feature.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| limit | No | Maximum number of trades to return | |
| trader | No | Filter by trader wallet address (0x...) | |
| status | No | Filter by trade status: open, closed, or won |
Implementation Reference
- src/tools/get-trade-history.ts:14-41 (handler)Main handler function for the config.history tool. Checks for Pro license, calls getTradeHistory DB query with optional filters (limit, trader, status), and formats results as a markdown table.
export async function handleGetTradeHistory(db: Database.Database, input: TradeHistoryInput): Promise<string> { const isPro = await checkLicense(); if (!isPro) { return requirePro("get_trade_history"); } const trades = getTradeHistory(db, { limit: input.limit, trader: input.trader, status: input.status, }); if (trades.length === 0) { return "No trades found."; } let output = `## Trade History (${trades.length})\n\n`; output += `| # | Time | Trader | Market | Price | Amount | Mode | Status |\n|---|------|--------|--------|-------|--------|------|--------|\n`; for (let i = 0; i < trades.length; i++) { const t = trades[i]; const time = t.created_at?.split("T")[1]?.slice(0, 5) ?? "-"; const addr = t.trader_address.slice(0, 6) + ".."; output += `| ${i + 1} | ${time} | ${addr} | ${t.market_slug ?? "-"} | $${t.price.toFixed(2)} | $${t.amount.toFixed(2)} | ${t.mode} | ${t.status} |\n`; } return output; } - src/tools/get-trade-history.ts:6-10 (schema)Zod schema for config.history input validation. Accepts optional limit (1-100, default 20), trader (wallet address), and status (open/closed/won) filters.
export const tradeHistorySchema = z.object({ limit: z.number().int().min(1).max(100).optional().default(20).describe("Maximum number of trades to return"), trader: z.string().optional().describe("Filter by trader wallet address (0x...)"), status: z.string().optional().describe("Filter by trade status: open, closed, or won"), }); - src/index.ts:197-202 (registration)Registration of the 'config.history' tool on the MCP server with description, schema, and handler wired to safe('trades.history', ...).
server.tool( "config.history", "Retrieve past copy trades from the database with optional filters by trader address or status. Returns trade details including entry price, P&L, and market info. Pro feature.", tradeHistorySchema.shape, safe("trades.history", async (input) => ({ content: [{ type: "text" as const, text: await handleGetTradeHistory(db, tradeHistorySchema.parse(input)) }] })) ); - src/db/queries.ts:83-99 (helper)Database query helper that builds a parameterized SQL query to fetch trades with optional filters by trader address and status, ordered by creation time descending.
export function getTradeHistory(db: Database.Database, opts: { limit?: number; trader?: string; status?: string }): TradeRecord[] { let sql = "SELECT * FROM trades WHERE 1=1"; const params: Record<string, unknown> = {}; if (opts.trader) { sql += " AND trader_address = @trader"; params.trader = opts.trader; } if (opts.status) { sql += " AND status = @status"; params.status = opts.status; } sql += " ORDER BY created_at DESC LIMIT @limit"; params.limit = opts.limit ?? 50; return db.prepare(sql).all(params) as TradeRecord[]; }