get_recent_trades
Fetch recent trades for a specific cryptocurrency pair on Binance. Retrieve up to 1000 recent transactions by specifying the trading symbol and optional limit to analyze market activity.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| limit | No | Number of trades to return, default 500, max 1000 | |
| symbol | Yes | Trading pair symbol, e.g. BTCUSDT |
Input Schema (JSON Schema)
{
"$schema": "http://json-schema.org/draft-07/schema#",
"additionalProperties": false,
"properties": {
"limit": {
"description": "Number of trades to return, default 500, max 1000",
"type": "number"
},
"symbol": {
"description": "Trading pair symbol, e.g. BTCUSDT",
"type": "string"
}
},
"required": [
"symbol"
],
"type": "object"
}
Implementation Reference
- src/index.ts:48-66 (handler)The handler function that executes the tool logic: fetches recent trades from the Binance API endpoint /api/v3/trades using axios, handles errors, and returns JSON-formatted response.async (args: { symbol: string; limit?: number }) => { try { const response = await axios.get(`${BASE_URL}/api/v3/trades`, { params: { symbol: args.symbol, limit: args.limit }, proxy: getProxy(), }); return { content: [{ type: "text", text: JSON.stringify(response.data, null, 2) }] }; } catch (error: any) { return { content: [{ type: "text", text: `Failed to get recent trades: ${error.message}` }], isError: true }; } }
- src/index.ts:45-47 (schema)Zod schema defining the input parameters for the tool: symbol (string, required) and limit (number, optional).symbol: z.string().describe("Trading pair symbol, e.g. BTCUSDT"), limit: z.number().optional().describe("Number of trades to return, default 500, max 1000") },
- src/index.ts:43-67 (registration)Registration of the 'get_recent_trades' tool using server.tool(), including inline schema and handler."get_recent_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") }, async (args: { symbol: string; limit?: number }) => { try { const response = await axios.get(`${BASE_URL}/api/v3/trades`, { params: { symbol: args.symbol, limit: args.limit }, proxy: getProxy(), }); return { content: [{ type: "text", text: JSON.stringify(response.data, null, 2) }] }; } catch (error: any) { return { content: [{ type: "text", text: `Failed to get recent trades: ${error.message}` }], isError: true }; } } );
- src/index.ts:403-412 (helper)Shared helper function to extract proxy configuration from environment variables, used in the axios request by the handler.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 }