get_crypto_market_data
Retrieve comprehensive cryptocurrency market data by providing a CoinGecko ID to access current prices, trading volumes, and market capitalization for informed trading decisions.
Instructions
Gets comprehensive market data for a cryptocurrency.
Args:
coin_id: CoinGecko ID (e.g., 'bitcoin', 'ethereum')
Returns:
Formatted string with market data
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| coin_id | Yes |
Implementation Reference
- tools/crypto_data.py:51-92 (handler)The core handler function implementing get_crypto_market_data. Fetches detailed market data (price, market cap, volume, changes, ATH/ATL) from CoinGecko API for a given coin_id and formats it into a readable string.def get_crypto_market_data(coin_id: str) -> str: """ Gets comprehensive market data for a cryptocurrency. Args: coin_id: CoinGecko ID (e.g., 'bitcoin', 'ethereum') Returns: Formatted string with market data """ try: data = cg.get_coin_by_id( id=coin_id, localization=False, tickers=False, market_data=True, community_data=False, developer_data=False ) market = data.get("market_data", {}) return f""" Crypto Market Data: {data.get('name', coin_id).upper()} Symbol: {data.get('symbol', 'N/A').upper()} -------------------------------- Current Price: ${market.get('current_price', {}).get('usd', 0):,.2f} Market Cap: ${market.get('market_cap', {}).get('usd', 0):,.0f} 24h Volume: ${market.get('total_volume', {}).get('usd', 0):,.0f} -------------------------------- 24h Change: {market.get('price_change_percentage_24h', 0):.2f}% 7d Change: {market.get('price_change_percentage_7d', 0):.2f}% 30d Change: {market.get('price_change_percentage_30d', 0):.2f}% -------------------------------- All-Time High: ${market.get('ath', {}).get('usd', 0):,.2f} ATH Date: {market.get('ath_date', {}).get('usd', 'N/A')[:10]} All-Time Low: ${market.get('atl', {}).get('usd', 0):,.2f} ATL Date: {market.get('atl_date', {}).get('usd', 'N/A')[:10]} """ except Exception as e: logger.error(f"CoinGecko error for {coin_id}: {e}") return f"Error fetching market data for {coin_id}: {str(e)}"
- server.py:415-418 (registration)Registration of the cryptocurrency tools, including get_crypto_market_data, via the register_tools helper which applies @mcp.tool() decorator to enable them in the MCP server.register_tools( [get_crypto_price, get_crypto_market_data, get_trending_crypto, search_crypto], "Cryptocurrency" )
- server.py:21-21 (registration)Import statement bringing get_crypto_market_data into the MCP server module for registration.from tools.crypto_data import get_crypto_price, get_crypto_market_data, get_trending_crypto, search_crypto