get_crypto_price
Retrieve current cryptocurrency prices from CoinGecko for trading analysis and portfolio management within MonteWalk's quantitative finance toolkit.
Instructions
Gets the current price of a cryptocurrency.
Args:
coin_id: CoinGecko ID (e.g., 'bitcoin', 'ethereum', 'solana')
vs_currency: Currency to compare against (default: 'usd')
Returns:
Dictionary with price information
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| coin_id | Yes | ||
| vs_currency | No | usd |
Implementation Reference
- tools/crypto_data.py:15-49 (handler)Main handler function for get_crypto_price tool. Fetches cryptocurrency price data from CoinGecko API, including price, market cap, 24h volume, and change.def get_crypto_price(coin_id: str, vs_currency: str = "usd") -> Dict[str, Any]: """ Gets the current price of a cryptocurrency. Args: coin_id: CoinGecko ID (e.g., 'bitcoin', 'ethereum', 'solana') vs_currency: Currency to compare against (default: 'usd') Returns: Dictionary with price information """ try: data = cg.get_price( ids=coin_id, vs_currencies=vs_currency, include_24hr_change=True, include_market_cap=True, include_24hr_vol=True ) if not data or coin_id not in data: return {"error": f"Coin '{coin_id}' not found"} coin_data = data[coin_id] return { "coin": coin_id, "price": coin_data.get(vs_currency, 0), "market_cap": coin_data.get(f"{vs_currency}_market_cap", 0), "24h_volume": coin_data.get(f"{vs_currency}_24h_vol", 0), "24h_change": coin_data.get(f"{vs_currency}_24h_change", 0), "currency": vs_currency.upper() } except Exception as e: logger.error(f"CoinGecko error for {coin_id}: {e}") return {"error": str(e)}
- server.py:415-418 (registration)Registers the get_crypto_price tool (and related crypto tools) with the MCP server using the register_tools helper, which applies the @mcp.tool() decorator.register_tools( [get_crypto_price, get_crypto_market_data, get_trending_crypto, search_crypto], "Cryptocurrency" )
- tools/crypto_data.py:12-13 (helper)Global CoinGeckoAPI client initialization used by get_crypto_price and other crypto tools.# Initialize CoinGecko client cg = CoinGeckoAPI()
- server.py:21-21 (registration)Import statement bringing get_crypto_price into the MCP server module for registration.from tools.crypto_data import get_crypto_price, get_crypto_market_data, get_trending_crypto, search_crypto