get-trades
Fetch recent trades for specific cryptocurrency trading pairs across exchanges using the CCXT MCP Server. Specify exchange, symbol, and limit to retrieve trade data efficiently.
Instructions
Get recent trades for a trading pair
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| exchange | Yes | Exchange ID (e.g., binance, coinbase) | |
| limit | No | Number of trades to fetch | |
| symbol | Yes | Trading pair symbol (e.g., BTC/USDT) |
Implementation Reference
- src/tools/public.ts:184-211 (handler)Executes the tool logic: fetches recent trades from the exchange using fetchTrades, with rate limiting via rateLimiter, caching via getCachedData, logging, and error handling.}, async ({ exchange, symbol, limit }) => { try { return await rateLimiter.execute(exchange, async () => { const ex = getExchange(exchange); const cacheKey = `trades:${exchange}:${symbol}:${limit}`; const trades = await getCachedData(cacheKey, async () => { log(LogLevel.INFO, `Fetching trades for ${symbol} on ${exchange}, limit: ${limit}`); return await ex.fetchTrades(symbol, undefined, limit); }); return { content: [{ type: "text", text: JSON.stringify(trades, null, 2) }] }; }); } catch (error) { log(LogLevel.ERROR, `Error fetching trades: ${error instanceof Error ? error.message : String(error)}`); return { content: [{ type: "text", text: `Error: ${error instanceof Error ? error.message : String(error)}` }], isError: true }; }
- src/tools/public.ts:181-183 (schema)Zod input schema defining parameters: exchange (string), symbol (string), limit (number, optional, default 50).exchange: z.string().describe("Exchange ID (e.g., binance, coinbase)"), symbol: z.string().describe("Trading pair symbol (e.g., BTC/USDT)"), limit: z.number().optional().default(50).describe("Number of trades to fetch")
- src/tools/public.ts:180-212 (registration)Registers the 'get-trades' tool on the MCP server with name, description, input schema, and inline handler function.server.tool("get-trades", "Get recent trades for a trading pair", { exchange: z.string().describe("Exchange ID (e.g., binance, coinbase)"), symbol: z.string().describe("Trading pair symbol (e.g., BTC/USDT)"), limit: z.number().optional().default(50).describe("Number of trades to fetch") }, async ({ exchange, symbol, limit }) => { try { return await rateLimiter.execute(exchange, async () => { const ex = getExchange(exchange); const cacheKey = `trades:${exchange}:${symbol}:${limit}`; const trades = await getCachedData(cacheKey, async () => { log(LogLevel.INFO, `Fetching trades for ${symbol} on ${exchange}, limit: ${limit}`); return await ex.fetchTrades(symbol, undefined, limit); }); return { content: [{ type: "text", text: JSON.stringify(trades, null, 2) }] }; }); } catch (error) { log(LogLevel.ERROR, `Error fetching trades: ${error instanceof Error ? error.message : String(error)}`); return { content: [{ type: "text", text: `Error: ${error instanceof Error ? error.message : String(error)}` }], isError: true }; } });