get_price
Retrieve current market prices for trading pairs on Binance to monitor cryptocurrency values and make informed trading decisions.
Instructions
获取指定交易对的当前价格
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| symbol | Yes | 交易对符号,如 BTCUSDT |
Implementation Reference
- src/tools/market-data.ts:28-42 (handler)The asynchronous handler function that validates input, fetches the current price for the given symbol from the Binance client, and returns the price data with timestamp.handler: async (binanceClient: any, args: unknown) => { const input = validateInput(GetPriceSchema, args); validateSymbol(input.symbol); try { const price = await binanceClient.prices({ symbol: input.symbol }); return { symbol: input.symbol, price: price[input.symbol], timestamp: Date.now(), }; } catch (error) { handleBinanceError(error); } },
- src/tools/market-data.ts:18-27 (schema)JSON Schema defining the input for the get_price tool, specifying the required 'symbol' string parameter.inputSchema: { type: 'object', properties: { symbol: { type: 'string', description: '交易对符号,如 BTCUSDT', }, }, required: ['symbol'], },
- src/types/mcp.ts:3-5 (schema)Zod schema for validating the get_price input, used within the handler.export const GetPriceSchema = z.object({ symbol: z.string().describe('交易对符号,如 BTCUSDT'), });
- src/tools/market-data.ts:15-43 (registration)The complete tool definition object for 'get_price', including name, description, inputSchema, and handler, within the marketDataTools export.{ name: 'get_price', description: '获取指定交易对的当前价格', inputSchema: { type: 'object', properties: { symbol: { type: 'string', description: '交易对符号,如 BTCUSDT', }, }, required: ['symbol'], }, handler: async (binanceClient: any, args: unknown) => { const input = validateInput(GetPriceSchema, args); validateSymbol(input.symbol); try { const price = await binanceClient.prices({ symbol: input.symbol }); return { symbol: input.symbol, price: price[input.symbol], timestamp: Date.now(), }; } catch (error) { handleBinanceError(error); } }, },
- src/server.ts:41-51 (registration)Server method that registers all tools, including get_price from marketDataTools, into the MCP server's tools Map.private setupTools(): void { const allTools = [ ...marketDataTools, ...accountTools, ...tradingTools, ]; for (const tool of allTools) { this.tools.set(tool.name, tool); } }