binance_market_price
Retrieve current cryptocurrency prices from Binance for trading pairs like BTCUSDT to monitor market values and inform investment decisions.
Instructions
Get the latest price for a symbol (e.g. BTCUSDT).
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| symbol | Yes |
Implementation Reference
- src/tools/market.ts:14-27 (handler)The main handler for the 'binance_market_price' tool. Defines the tool object with name, description, input schema reference, and the async run function that validates input, fetches the ticker price via the binance client, returns the data, or throws a wrapped error.export const tool_market_price: BinanceTool = { name: "binance_market_price", description: "Get the latest price for a symbol (e.g. BTCUSDT).", parameters: priceSchema, async run(input) { const params = priceSchema.parse(input); try { const res = await binance.tickerPrice(params.symbol); return res.data; } catch (err) { throw toToolError(err); } } };
- src/tools/market.ts:6-6 (schema)Zod schema for input validation: requires a 'symbol' string (e.g., BTCUSDT). Used in the tool's parameters and parsed in the run handler.const priceSchema = z.object({ symbol: z.string().min(1) });
- src/index.ts:15-23 (registration)The tool_market_price is imported (line 3) and included in the array of tools to be registered with the MCP server.const tools = [ tool_market_price, tool_market_klines, tool_exchange_info, tool_account_balances, tool_open_orders, tool_place_order, tool_cancel_order, ];
- src/index.ts:25-40 (registration)Loop that registers each tool (including binance_market_price) to the FastMCP server, copying name/desc/schema and wrapping the tool's run method in an execute handler that stringifies output and handles errors.tools.forEach((tool) => { server.addTool({ name: tool.name, description: tool.description, parameters: tool.parameters, execute: async (args) => { try { const result = await tool.run(args); return JSON.stringify(result, null, 2); } catch (error) { const handled = error instanceof ToolError ? error : new ToolError((error as Error).message); throw handled; } }, }); });