get_24hr_ticker
Retrieve 24-hour price change statistics for cryptocurrency trading pairs on Binance, including price movements and trading volume data.
Instructions
获取24小时价格变动统计
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| symbol | No | 交易对符号,不传则获取所有交易对 |
Implementation Reference
- src/tools/market-data.ts:163-187 (handler)The handler function for the 'get_24hr_ticker' tool. It validates input using Get24hrTickerSchema, optionally validates symbol, fetches 24hr ticker stats from Binance API using dailyStats, handles single symbol or all, and returns formatted data with timestamp or propagates errors.handler: async (binanceClient: any, args: unknown) => { const input = validateInput(Get24hrTickerSchema, args); if (input.symbol) { validateSymbol(input.symbol); } try { if (input.symbol) { const ticker = await binanceClient.dailyStats({ symbol: input.symbol }); return { symbol: input.symbol, data: ticker, timestamp: Date.now(), }; } else { const tickers = await binanceClient.dailyStats(); return { data: Array.isArray(tickers) ? tickers : [tickers], timestamp: Date.now(), }; } } catch (error) { handleBinanceError(error); }
- src/tools/market-data.ts:153-162 (schema)The inputSchema defined for the MCP tool 'get_24hr_ticker', specifying optional symbol parameter.inputSchema: { type: 'object', properties: { symbol: { type: 'string', description: '交易对符号,不传则获取所有交易对', }, }, required: [], },
- src/types/mcp.ts:18-20 (schema)Zod schema Get24hrTickerSchema used for input validation in the handler.export const Get24hrTickerSchema = z.object({ symbol: z.string().optional().describe('交易对符号,不传则获取所有交易对'), });
- src/server.ts:48-50 (registration)Registration loop in MCP server setupTools() that adds 'get_24hr_ticker' (from marketDataTools) to the tools Map by name for handling list_tools and call_tool requests.for (const tool of allTools) { this.tools.set(tool.name, tool); }
- src/server.ts:42-46 (registration)Combines tool arrays including marketDataTools (containing get_24hr_ticker) for registration in MCP server.const allTools = [ ...marketDataTools, ...accountTools, ...tradingTools, ];