batch-get-tickers
Retrieve real-time ticker data for multiple trading pairs simultaneously on supported exchanges. Specify exchange, symbols, and market type for efficient data fetching.
Instructions
Get ticker information for multiple trading pairs at once
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| exchange | Yes | Exchange ID (e.g., binance, coinbase) | |
| marketType | No | Market type (default: spot) | |
| symbols | Yes | List of trading pair symbols (e.g., ['BTC/USDT', 'ETH/USDT']) |
Input Schema (JSON Schema)
{
"$schema": "http://json-schema.org/draft-07/schema#",
"additionalProperties": false,
"properties": {
"exchange": {
"description": "Exchange ID (e.g., binance, coinbase)",
"type": "string"
},
"marketType": {
"description": "Market type (default: spot)",
"enum": [
"spot",
"future",
"swap",
"option",
"margin"
],
"type": "string"
},
"symbols": {
"description": "List of trading pair symbols (e.g., ['BTC/USDT', 'ETH/USDT'])",
"items": {
"type": "string"
},
"type": "array"
}
},
"required": [
"exchange",
"symbols"
],
"type": "object"
}
Implementation Reference
- src/tools/public.ts:73-102 (handler)The core handler function for the batch-get-tickers tool. It uses rate limiting, caching, fetches the appropriate exchange instance, and calls ex.fetchTickers(symbols) to retrieve ticker data for multiple symbols. Returns JSON stringified response or error.}, async ({ exchange, symbols, marketType }) => { try { return await rateLimiter.execute(exchange, async () => { const ex = marketType ? getExchangeWithMarketType(exchange, marketType) : getExchange(exchange); const cacheKey = `tickers:${exchange}:${marketType || 'spot'}:${symbols.join(',')}`; const tickers = await getCachedData(cacheKey, async () => { log(LogLevel.INFO, `Batch fetching tickers for ${symbols.length} symbols on ${exchange}`); return await ex.fetchTickers(symbols); }); return { content: [{ type: "text", text: JSON.stringify(tickers, null, 2) }] }; }); } catch (error) { log(LogLevel.ERROR, `Error batch fetching tickers: ${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:70-72 (schema)Zod input schema defining parameters for the tool: exchange (string), symbols (array of strings), and optional marketType (enum).exchange: z.string().describe("Exchange ID (e.g., binance, coinbase)"), symbols: z.array(z.string()).describe("List of trading pair symbols (e.g., ['BTC/USDT', 'ETH/USDT'])"), marketType: z.enum(["spot", "future", "swap", "option", "margin"]).optional().describe("Market type (default: spot)")
- src/tools/public.ts:69-103 (registration)Registration of the batch-get-tickers tool with McpServer using server.tool(), providing name, description, input schema, and inline handler function.server.tool("batch-get-tickers", "Get ticker information for multiple trading pairs at once", { exchange: z.string().describe("Exchange ID (e.g., binance, coinbase)"), symbols: z.array(z.string()).describe("List of trading pair symbols (e.g., ['BTC/USDT', 'ETH/USDT'])"), marketType: z.enum(["spot", "future", "swap", "option", "margin"]).optional().describe("Market type (default: spot)") }, async ({ exchange, symbols, marketType }) => { try { return await rateLimiter.execute(exchange, async () => { const ex = marketType ? getExchangeWithMarketType(exchange, marketType) : getExchange(exchange); const cacheKey = `tickers:${exchange}:${marketType || 'spot'}:${symbols.join(',')}`; const tickers = await getCachedData(cacheKey, async () => { log(LogLevel.INFO, `Batch fetching tickers for ${symbols.length} symbols on ${exchange}`); return await ex.fetchTickers(symbols); }); return { content: [{ type: "text", text: JSON.stringify(tickers, null, 2) }] }; }); } catch (error) { log(LogLevel.ERROR, `Error batch fetching tickers: ${error instanceof Error ? error.message : String(error)}`); return { content: [{ type: "text", text: `Error: ${error instanceof Error ? error.message : String(error)}` }], isError: true }; } });