Skip to main content
Glama
snjyor

Binance Cryptocurrency MCP

by snjyor

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
NameRequiredDescriptionDefault
fromIdNoTrade ID to start from, default returns the most recent trades
limitNoNumber of trades to return, default 500, max 1000
symbolYesTrading pair symbol, e.g. BTCUSDT

Implementation Reference

  • 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 }; } }
  • 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 }; } } );
  • 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 }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/snjyor/binance-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server