get_historical_trades
Retrieve historical trade data for specified cryptocurrency pairs from Binance, including trade IDs, quantities, and timestamps, enabling detailed market analysis.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| fromId | No | Trade ID to start from, default returns the most recent trades | |
| limit | No | Number of trades to return, default 500, max 1000 | |
| symbol | Yes | Trading pair symbol, e.g. BTCUSDT |
Implementation Reference
- src/index.ts:77-99 (handler)Executes the tool logic by calling Binance API endpoint /api/v3/historicalTrades with provided parameters, authenticates with optional API key, applies proxy if set, and returns formatted JSON response or error.async (args: { symbol: string; limit?: number; fromId?: number }) => { try { const response = await axios.get(`${BASE_URL}/api/v3/historicalTrades`, { params: { symbol: args.symbol, limit: args.limit, fromId: args.fromId }, headers: { "X-MBX-APIKEY": process.env.BINANCE_API_KEY || "" }, proxy: getProxy(), }); return { content: [{ type: "text", text: JSON.stringify(response.data, null, 2) }] }; } catch (error: any) { return { content: [{ type: "text", text: `Failed to get historical trades: ${error.message}` }], isError: true }; } }
- src/index.ts:72-76 (schema)Zod schema for input validation: requires 'symbol' string, optional 'limit' and 'fromId' numbers.{ symbol: z.string().describe("Trading pair symbol, e.g. BTCUSDT"), limit: z.number().optional().describe("Number of trades to return, default 500, max 1000"), fromId: z.number().optional().describe("Trade ID to start from, default returns the most recent trades") },
- src/index.ts:70-100 (registration)Registers the tool using McpServer.tool() method within the registerTools function.server.tool( "get_historical_trades", { symbol: z.string().describe("Trading pair symbol, e.g. BTCUSDT"), limit: z.number().optional().describe("Number of trades to return, default 500, max 1000"), fromId: z.number().optional().describe("Trade ID to start from, default returns the most recent trades") }, async (args: { symbol: string; limit?: number; fromId?: number }) => { try { const response = await axios.get(`${BASE_URL}/api/v3/historicalTrades`, { params: { symbol: args.symbol, limit: args.limit, fromId: args.fromId }, headers: { "X-MBX-APIKEY": process.env.BINANCE_API_KEY || "" }, proxy: getProxy(), }); return { content: [{ type: "text", text: JSON.stringify(response.data, null, 2) }] }; } catch (error: any) { return { content: [{ type: "text", text: `Failed to get historical trades: ${error.message}` }], isError: true }; } } );
- src/index.ts:403-412 (helper)Utility function to parse proxy configuration from HTTP_PROXY or HTTPS_PROXY environment variables, used in API requests.function getProxy():any { const proxy: any = {} if (proxyURL) { const urlInfo = new URL(proxyURL); proxy.host = urlInfo.hostname; proxy.port = urlInfo.port; proxy.protocol = urlInfo.protocol.replace(":", ""); } return proxy }