fetchTrades
Retrieve recent trades for a specific cryptocurrency pair on supported exchanges via the CCXT MCP Server, enabling precise data access for analysis and decision-making.
Instructions
Fetch recent trades for a symbol on an exchange
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| exchangeId | Yes | Exchange ID (e.g., 'binance', 'coinbase') | |
| limit | No | Limit the number of trades returned (optional) | |
| since | No | Timestamp in ms to fetch trades since (optional) | |
| symbol | Yes | Trading symbol (e.g., 'BTC/USDT') |
Input Schema (JSON Schema)
{
"$schema": "http://json-schema.org/draft-07/schema#",
"additionalProperties": false,
"properties": {
"exchangeId": {
"description": "Exchange ID (e.g., 'binance', 'coinbase')",
"type": "string"
},
"limit": {
"description": "Limit the number of trades returned (optional)",
"type": "number"
},
"since": {
"description": "Timestamp in ms to fetch trades since (optional)",
"type": "number"
},
"symbol": {
"description": "Trading symbol (e.g., 'BTC/USDT')",
"type": "string"
}
},
"required": [
"exchangeId",
"symbol"
],
"type": "object"
}
Implementation Reference
- src/tools/market-tools.ts:167-192 (handler)The handler function for the fetchTrades tool. It retrieves a public CCXT exchange instance and calls fetchTrades(symbol, since, limit), returning the trades as JSON or an error message.async ({ exchangeId, symbol, since, limit }) => { try { // 공개 인스턴스 사용 const exchange = ccxtServer.getPublicExchangeInstance(exchangeId); const trades = await exchange.fetchTrades(symbol, since, limit); return { content: [ { type: "text", text: JSON.stringify(trades, null, 2) } ] }; } catch (error) { return { content: [ { type: "text", text: `Error fetching trades: ${(error as Error).message}` } ], isError: true }; } }
- src/tools/market-tools.ts:161-166 (schema)Zod input schema for fetchTrades tool parameters: exchangeId (string), symbol (string), since (optional number), limit (optional number).{ exchangeId: z.string().describe("Exchange ID (e.g., 'binance', 'coinbase')"), symbol: z.string().describe("Trading symbol (e.g., 'BTC/USDT')"), since: z.number().optional().describe("Timestamp in ms to fetch trades since (optional)"), limit: z.number().optional().describe("Limit the number of trades returned (optional)") },
- src/tools/market-tools.ts:158-192 (registration)Direct registration of the fetchTrades tool within the registerMarketTools function, including name, description, schema, and handler.server.tool( "fetchTrades", "Fetch recent trades for a symbol on an exchange", { exchangeId: z.string().describe("Exchange ID (e.g., 'binance', 'coinbase')"), symbol: z.string().describe("Trading symbol (e.g., 'BTC/USDT')"), since: z.number().optional().describe("Timestamp in ms to fetch trades since (optional)"), limit: z.number().optional().describe("Limit the number of trades returned (optional)") }, async ({ exchangeId, symbol, since, limit }) => { try { // 공개 인스턴스 사용 const exchange = ccxtServer.getPublicExchangeInstance(exchangeId); const trades = await exchange.fetchTrades(symbol, since, limit); return { content: [ { type: "text", text: JSON.stringify(trades, null, 2) } ] }; } catch (error) { return { content: [ { type: "text", text: `Error fetching trades: ${(error as Error).message}` } ], isError: true }; } }
- src/server.ts:372-372 (registration)Top-level call to registerMarketTools in CcxtMcpServer's registerTools method, which registers the fetchTrades tool among others.registerMarketTools(this.server, this);