get_symbol_price
Fetch real-time cryptocurrency pair prices directly from Binance using the provided symbol (e.g., BTCUSDT). Retrieve accurate price data for trading or analysis.
Instructions
Get the current price of a cryptocurrency pair.
Args: symbol: The cryptocurrency pair, e.g., BTCUSDT.
Returns: Price information from Binance.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| symbol | Yes |
Implementation Reference
- binance.py:26-44 (handler)The handler function for the 'get_symbol_price' tool. It is decorated with @mcp.tool() for registration and @lru_cache for caching. Fetches the current price of a given symbol from the Binance spot API.@mcp.tool() @lru_cache(maxsize=100) def get_symbol_price(symbol: str) -> Any: """ Get the current price of a cryptocurrency pair. Args: symbol: The cryptocurrency pair, e.g., BTCUSDT. Returns: Price information from Binance. """ url = "https://api.binance.com/api/v3/ticker/price" params = {"symbol": symbol} response = requests.get(url, params=params) if response.status_code == 200: data = response.json() return {"price": data['price'], "symbol": symbol} return {"error": response.text}
- binance.py:26-26 (registration)The @mcp.tool() decorator registers the get_symbol_price function as an MCP tool.@mcp.tool()
- binance.py:29-37 (schema)Docstring defining the input schema (symbol: str) and output format for the tool.""" Get the current price of a cryptocurrency pair. Args: symbol: The cryptocurrency pair, e.g., BTCUSDT. Returns: Price information from Binance. """