get-price
Fetch current cryptocurrency prices from major exchanges like Binance, Coinbase, and Kraken by specifying trading pairs such as BTC/USDT or ETH/USDT.
Instructions
Get current price of a cryptocurrency pair from a specific exchange
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| symbol | Yes | Trading pair symbol (e.g., BTC/USDT, ETH/USDT) | |
| exchange | No | Exchange to use (supported: binance, coinbase, kraken, kucoin, hyperliquid, huobi, bitfinex, bybit, okx, mexc) | binance |
Implementation Reference
- src/server.py:105-119 (registration)Registration of the 'get-price' tool in the handle_list_tools function, defining its name, description, and input schema.types.Tool( name="get-price", description="Get current price of a cryptocurrency pair from a specific exchange", inputSchema={ "type": "object", "properties": { "symbol": { "type": "string", "description": "Trading pair symbol (e.g., BTC/USDT, ETH/USDT)", }, "exchange": get_exchange_schema() }, "required": ["symbol"], }, ),
- src/server.py:242-251 (handler)The core handler logic for the 'get-price' tool within the handle_call_tool function. It retrieves the ticker data using ccxt and returns the current last price.if name == "get-price": symbol = arguments.get("symbol", "").upper() ticker = await exchange.fetch_ticker(symbol) return [ types.TextContent( type="text", text=f"Current price of {symbol} on {exchange_id.upper()}: {ticker['last']} {symbol.split('/')[1]}" ) ]
- src/server.py:108-118 (schema)Input schema definition for the 'get-price' tool, specifying required 'symbol' parameter and optional 'exchange'.inputSchema={ "type": "object", "properties": { "symbol": { "type": "string", "description": "Trading pair symbol (e.g., BTC/USDT, ETH/USDT)", }, "exchange": get_exchange_schema() }, "required": ["symbol"], },
- src/server.py:59-66 (helper)Helper function that generates the JSON schema for selecting supported exchanges, referenced in the 'get-price' tool's input schema.def get_exchange_schema() -> Dict[str, Any]: """Get the JSON schema for exchange selection.""" return { "type": "string", "description": f"Exchange to use (supported: {', '.join(SUPPORTED_EXCHANGES.keys())})", "enum": list(SUPPORTED_EXCHANGES.keys()), "default": "binance" }
- src/server.py:31-41 (helper)Helper function to retrieve or initialize a CCXT exchange instance, used by the 'get-price' handler.async def get_exchange(exchange_id: str) -> ccxt.Exchange: """Get or create an exchange instance.""" exchange_id = exchange_id.lower() if exchange_id not in SUPPORTED_EXCHANGES: raise ValueError(f"Unsupported exchange: {exchange_id}") if exchange_id not in exchange_instances: exchange_class = SUPPORTED_EXCHANGES[exchange_id] exchange_instances[exchange_id] = exchange_class() return exchange_instances[exchange_id]