Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Access CoinGecko crypto market data: spot prices, OHLC, trending coins, exchange listings, NFTs, and global stats.
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
coingecko.py
1"""2CoinGecko Tool Wrappers34Wraps tools from /tools/coingecko/ for use in Agent framework.5Provides price data, charts, market discovery, global stats, derivatives,6exchanges, NFTs, infrastructure, search, and contract lookups.7"""8import asyncio9import logging10from typing import List, Optional1112from core.tool import BaseTool, ToolContext, ToolResult1314logger = logging.getLogger(__name__)1516# Import original tools from local tools directory17try:18from .tools.coin_prices import get_coin_prices_at_timestamps19from .tools.coin_ohlc_range_by_id import get_coin_ohlc_range_by_id20from .tools.coin_historical_chart_range_by_id import get_coin_historical_chart_range_by_id21from .tools.market_discovery import (22get_trending,23get_top_gainers_losers,24get_new_coins,25)26from .tools.global_data import (27get_global,28get_global_defi,29)30from .tools.derivatives import (31get_derivatives,32get_derivatives_exchanges,33get_categories,34)35# New imports for expanded API coverage36from .tools.coins import (37get_coins_list,38get_coins_markets,39get_coin_data,40get_coin_tickers,41)42from .tools.exchanges import (43get_exchanges,44get_exchange,45get_exchange_tickers,46get_exchange_volume_chart,47)48from .tools.nfts import (49get_nfts_list,50get_nft,51get_nft_by_contract,52)53from .tools.infrastructure import (54get_asset_platforms,55get_exchange_rates,56get_vs_currencies,57get_categories_list,58)59from .tools.search import search60from .tools.contracts import (61get_token_price,62get_coin_by_contract,63)64COINGECKO_AVAILABLE = True65except ImportError as e:66logger.warning(f"CoinGecko tools not available: {e}")67COINGECKO_AVAILABLE = False686970class CoinPriceTool(BaseTool):71"""72Get cryptocurrency prices at specific timestamps.7374Supports current price ("now") and historical prices.75Accepts coin IDs (bitcoin, ethereum) or symbols (BTC, ETH).76"""7778@property79def name(self) -> str:80return "coin_price"8182@property83def description(self) -> str:84return """Get cryptocurrency prices. Supports current ("now") and historical prices.8586If unsure about the coin ID, first use cg_search to find the correct ID.8788Examples:89- Get BTC current price: coin_price(coin_ids="bitcoin")90- Get multiple coins: coin_price(coin_ids="BTC,ETH,SOL")91- Get historical price: coin_price(coin_ids="bitcoin", timestamps=["2024-01-01"])"""9293@property94def parameters(self) -> dict:95return {96"type": "object",97"properties": {98"coin_ids": {99"type": "string",100"description": "Coin ID or symbol (bitcoin, BTC) or comma-separated list (BTC,ETH,SOL)"101},102"timestamps": {103"type": "array",104"items": {"type": "string"},105"description": "List of timestamps. Use 'now' for current price, or date strings like '2024-01-01'",106"default": ["now"]107},108"vs_currency": {109"type": "string",110"description": "Target currency (usd, eur, btc)",111"default": "usd"112}113},114"required": ["coin_ids"]115}116117async def execute(118self,119ctx: ToolContext,120coin_ids: str,121timestamps: Optional[List[str]] = None,122vs_currency: str = "usd"123) -> ToolResult:124if not COINGECKO_AVAILABLE:125return ToolResult(126success=False,127output=None,128error="CoinGecko tools not available. Check if /tools/coingecko exists."129)130131try:132result = await asyncio.to_thread(133get_coin_prices_at_timestamps,134coin_ids=coin_ids,135timestamps=timestamps or ["now"],136vs_currency=vs_currency137)138return ToolResult(success=True, output=result)139except Exception as e:140return ToolResult(success=False, output=None, error=str(e))141142143class CoinOHLCTool(BaseTool):144"""145Get OHLC (candlestick) data for a cryptocurrency.146"""147148@property149def name(self) -> str:150return "coin_ohlc"151152@property153def description(self) -> str:154return """Get OHLC candlestick data for technical analysis.155156Examples:157- Get BTC daily OHLC for last 30 days: coin_ohlc(coin_id="bitcoin", days=30)158- Get ETH 4h candles: coin_ohlc(coin_id="ethereum", days=7)"""159160@property161def parameters(self) -> dict:162return {163"type": "object",164"properties": {165"coin_id": {166"type": "string",167"description": "CoinGecko coin ID (bitcoin, ethereum, solana)"168},169"days": {170"type": "integer",171"description": "Number of days (1, 7, 14, 30, 90, 180, 365)",172"default": 30173},174"vs_currency": {175"type": "string",176"description": "Target currency",177"default": "usd"178}179},180"required": ["coin_id"]181}182183async def execute(184self,185ctx: ToolContext,186coin_id: str,187days: int = 30,188vs_currency: str = "usd"189) -> ToolResult:190if not COINGECKO_AVAILABLE:191return ToolResult(192success=False,193output=None,194error="CoinGecko tools not available."195)196197try:198import time199to_timestamp = int(time.time())200from_timestamp = to_timestamp - (days * 24 * 60 * 60)201202result = await asyncio.to_thread(203get_coin_ohlc_range_by_id,204coin_id=coin_id,205from_timestamp=from_timestamp,206to_timestamp=to_timestamp207)208return ToolResult(success=True, output=result)209except Exception as e:210return ToolResult(success=False, output=None, error=str(e))211212213class CoinChartTool(BaseTool):214"""215Get historical price chart data for a cryptocurrency.216"""217218@property219def name(self) -> str:220return "coin_chart"221222@property223def description(self) -> str:224return """Get historical price chart data (prices, market caps, volumes).225226Examples:227- Get BTC 30-day chart: coin_chart(coin_id="bitcoin", days=30)228- Get ETH 7-day chart: coin_chart(coin_id="ethereum", days=7)"""229230@property231def parameters(self) -> dict:232return {233"type": "object",234"properties": {235"coin_id": {236"type": "string",237"description": "CoinGecko coin ID"238},239"days": {240"type": "integer",241"description": "Number of days of data",242"default": 30243},244"vs_currency": {245"type": "string",246"default": "usd"247}248},249"required": ["coin_id"]250}251252async def execute(253self,254ctx: ToolContext,255coin_id: str,256days: int = 30,257vs_currency: str = "usd"258) -> ToolResult:259if not COINGECKO_AVAILABLE:260return ToolResult(261success=False,262output=None,263error="CoinGecko tools not available."264)265266try:267import time268to_timestamp = int(time.time())269from_timestamp = to_timestamp - (days * 24 * 60 * 60)270271result = await asyncio.to_thread(272get_coin_historical_chart_range_by_id,273coin_id=coin_id,274vs_currency=vs_currency,275from_timestamp=from_timestamp,276to_timestamp=to_timestamp277)278return ToolResult(success=True, output=result)279except Exception as e:280return ToolResult(success=False, output=None, error=str(e))281282283# ==================== Market Discovery Tools ====================284285class CoinGeckoTrendingTool(BaseTool):286"""287Get trending coins based on user search data.288"""289290@property291def name(self) -> str:292return "cg_trending"293294@property295def description(self) -> str:296return """Get trending coins in the last 24 hours based on user search data.297298Also returns trending NFTs and categories.299300Examples:301- Get trending: cg_trending()"""302303@property304def parameters(self) -> dict:305return {306"type": "object",307"properties": {}308}309310async def execute(self, ctx: ToolContext) -> ToolResult:311if not COINGECKO_AVAILABLE:312return ToolResult(313success=False,314output=None,315error="CoinGecko tools not available."316)317318try:319result = await asyncio.to_thread(get_trending)320return ToolResult(success=True, output=result)321except Exception as e:322return ToolResult(success=False, output=None, error=str(e))323324325class CoinGeckoTopGainersLosersTool(BaseTool):326"""327Get top gainers and losers by price change.328"""329330@property331def name(self) -> str:332return "cg_top_gainers_losers"333334@property335def description(self) -> str:336return """Get top 30 gainers and losers by price change percentage.337338Examples:339- Get 24h movers: cg_top_gainers_losers()340- Get 7d movers: cg_top_gainers_losers(duration="7d")"""341342@property343def parameters(self) -> dict:344return {345"type": "object",346"properties": {347"vs_currency": {348"type": "string",349"description": "Target currency",350"default": "usd"351},352"duration": {353"type": "string",354"description": "Time duration: 1h, 24h, 7d, 14d, 30d, 60d, 1y",355"default": "24h"356}357}358}359360async def execute(361self,362ctx: ToolContext,363vs_currency: str = "usd",364duration: str = "24h"365) -> ToolResult:366if not COINGECKO_AVAILABLE:367return ToolResult(368success=False,369output=None,370error="CoinGecko tools not available."371)372373try:374result = await asyncio.to_thread(get_top_gainers_losers, vs_currency, duration)375return ToolResult(success=True, output=result)376except Exception as e:377return ToolResult(success=False, output=None, error=str(e))378379380class CoinGeckoNewCoinsTool(BaseTool):381"""382Get recently added coins.383"""384385@property386def name(self) -> str:387return "cg_new_coins"388389@property390def description(self) -> str:391return """Get recently added coins to CoinGecko.392393Examples:394- Get new coins: cg_new_coins()"""395396@property397def parameters(self) -> dict:398return {399"type": "object",400"properties": {}401}402403async def execute(self, ctx: ToolContext) -> ToolResult:404if not COINGECKO_AVAILABLE:405return ToolResult(406success=False,407output=None,408error="CoinGecko tools not available."409)410411try:412result = await asyncio.to_thread(get_new_coins)413return ToolResult(success=True, output=result)414except Exception as e:415return ToolResult(success=False, output=None, error=str(e))416417418# ==================== Global Data Tools ====================419420class CoinGeckoGlobalTool(BaseTool):421"""422Get global cryptocurrency market statistics.423"""424425@property426def name(self) -> str:427return "cg_global"428429@property430def description(self) -> str:431return """Get global cryptocurrency market statistics.432433Returns total market cap, volume, BTC dominance, and more.434435Examples:436- Get global stats: cg_global()"""437438@property439def parameters(self) -> dict:440return {441"type": "object",442"properties": {}443}444445async def execute(self, ctx: ToolContext) -> ToolResult:446if not COINGECKO_AVAILABLE:447return ToolResult(448success=False,449output=None,450error="CoinGecko tools not available."451)452453try:454result = await asyncio.to_thread(get_global)455return ToolResult(success=True, output=result)456except Exception as e:457return ToolResult(success=False, output=None, error=str(e))458459460class CoinGeckoGlobalDefiTool(BaseTool):461"""462Get global DeFi market statistics.463"""464465@property466def name(self) -> str:467return "cg_global_defi"468469@property470def description(self) -> str:471return """Get global DeFi market statistics.472473Returns DeFi market cap, TVL, DeFi dominance.474475Examples:476- Get DeFi stats: cg_global_defi()"""477478@property479def parameters(self) -> dict:480return {481"type": "object",482"properties": {}483}484485async def execute(self, ctx: ToolContext) -> ToolResult:486if not COINGECKO_AVAILABLE:487return ToolResult(488success=False,489output=None,490error="CoinGecko tools not available."491)492493try:494result = await asyncio.to_thread(get_global_defi)495return ToolResult(success=True, output=result)496except Exception as e:497return ToolResult(success=False, output=None, error=str(e))498499500# ==================== Derivatives Tools ====================501502class CoinGeckoDerivativesTool(BaseTool):503"""504Get all derivatives tickers.505"""506507@property508def name(self) -> str:509return "cg_derivatives"510511@property512def description(self) -> str:513return """Get all derivatives tickers (perpetuals, futures).514515Includes funding rates, open interest, spread, basis.516517Examples:518- Get all derivatives: cg_derivatives()519- Get unexpired only: cg_derivatives(include_tickers="unexpired")"""520521@property522def parameters(self) -> dict:523return {524"type": "object",525"properties": {526"include_tickers": {527"type": "string",528"description": "Filter: all or unexpired",529"default": "unexpired"530}531}532}533534async def execute(535self,536ctx: ToolContext,537include_tickers: str = "unexpired"538) -> ToolResult:539if not COINGECKO_AVAILABLE:540return ToolResult(541success=False,542output=None,543error="CoinGecko tools not available."544)545546try:547result = await asyncio.to_thread(get_derivatives, include_tickers)548return ToolResult(success=True, output=result)549except Exception as e:550return ToolResult(success=False, output=None, error=str(e))551552553class CoinGeckoDerivativesExchangesTool(BaseTool):554"""555Get derivatives exchanges with rankings.556"""557558@property559def name(self) -> str:560return "cg_derivatives_exchanges"561562@property563def description(self) -> str:564return """Get list of derivatives exchanges with ranking.565566Sorted by open interest or volume.567568Examples:569- Get exchanges by OI: cg_derivatives_exchanges()570- Get exchanges by volume: cg_derivatives_exchanges(order="trade_volume_24h_btc_desc")"""571572@property573def parameters(self) -> dict:574return {575"type": "object",576"properties": {577"order": {578"type": "string",579"description": "Sort order",580"default": "open_interest_btc_desc"581},582"per_page": {583"type": "integer",584"description": "Results per page (max 100)",585"default": 50586}587}588}589590async def execute(591self,592ctx: ToolContext,593order: str = "open_interest_btc_desc",594per_page: int = 50595) -> ToolResult:596if not COINGECKO_AVAILABLE:597return ToolResult(598success=False,599output=None,600error="CoinGecko tools not available."601)602603try:604result = await asyncio.to_thread(get_derivatives_exchanges, order, per_page)605return ToolResult(success=True, output=result)606except Exception as e:607return ToolResult(success=False, output=None, error=str(e))608609610class CoinGeckoCategoriesjTool(BaseTool):611"""612Get coin categories with market data.613"""614615@property616def name(self) -> str:617return "cg_categories"618619@property620def description(self) -> str:621return """Get coin categories with market data (DeFi, L1, L2, Memes, etc.).622623See sector performance and top coins in each category.624625Examples:626- Get categories by market cap: cg_categories()627- Get categories by 24h change: cg_categories(order="market_cap_change_24h_desc")"""628629@property630def parameters(self) -> dict:631return {632"type": "object",633"properties": {634"order": {635"type": "string",636"description": "Sort order: market_cap_desc, market_cap_change_24h_desc, etc.",637"default": "market_cap_desc"638}639}640}641642async def execute(643self,644ctx: ToolContext,645order: str = "market_cap_desc"646) -> ToolResult:647if not COINGECKO_AVAILABLE:648return ToolResult(649success=False,650output=None,651error="CoinGecko tools not available."652)653654try:655result = await asyncio.to_thread(get_categories, order)656return ToolResult(success=True, output=result)657except Exception as e:658return ToolResult(success=False, output=None, error=str(e))659660661# ==================== Coin Data Tools ====================662663class CoinGeckoCoinsListTool(BaseTool):664"""665Get all supported coins with IDs, names, and symbols.666"""667668@property669def name(self) -> str:670return "cg_coins_list"671672@property673def description(self) -> str:674return """Get all supported coins with id, symbol, and name.675676Useful for coin discovery and ID lookup.677678Examples:679- Get all coins: cg_coins_list()680- Get coins with platform addresses: cg_coins_list(include_platform=True)"""681682@property683def parameters(self) -> dict:684return {685"type": "object",686"properties": {687"include_platform": {688"type": "boolean",689"description": "Include platform contract addresses",690"default": False691}692}693}694695async def execute(696self,697ctx: ToolContext,698include_platform: bool = False699) -> ToolResult:700if not COINGECKO_AVAILABLE:701return ToolResult(702success=False,703output=None,704error="CoinGecko tools not available."705)706707try:708result = await asyncio.to_thread(get_coins_list, include_platform)709return ToolResult(success=True, output=result)710except Exception as e:711return ToolResult(success=False, output=None, error=str(e))712713714class CoinGeckoCoinsMarketsTool(BaseTool):715"""716Get bulk market data for coins with sorting and filtering.717"""718719@property720def name(self) -> str:721return "cg_coins_markets"722723@property724def description(self) -> str:725return """Get market data for coins with sorting, filtering, and pagination.726727Screen coins by market cap, volume, price change, or category.728729Examples:730- Get top 100 by market cap: cg_coins_markets()731- Get top by volume: cg_coins_markets(order="volume_desc")732- Get DeFi coins: cg_coins_markets(category="decentralized-finance-defi")733- Get specific coins: cg_coins_markets(ids="bitcoin,ethereum,solana")"""734735@property736def parameters(self) -> dict:737return {738"type": "object",739"properties": {740"vs_currency": {741"type": "string",742"description": "Target currency (usd, eur, btc)",743"default": "usd"744},745"order": {746"type": "string",747"description": "Sort order: market_cap_desc, volume_desc, price_change_24h_desc",748"default": "market_cap_desc"749},750"per_page": {751"type": "integer",752"description": "Results per page (max 250)",753"default": 100754},755"page": {756"type": "integer",757"description": "Page number",758"default": 1759},760"sparkline": {761"type": "boolean",762"description": "Include 7-day sparkline data",763"default": False764},765"price_change_percentage": {766"type": "string",767"description": "Price change periods (comma-separated): 1h, 24h, 7d, 14d, 30d, 200d, 1y",768"default": "24h"769},770"category": {771"type": "string",772"description": "Filter by category id"773},774"ids": {775"type": "string",776"description": "Comma-separated coin ids to filter"777}778}779}780781async def execute(782self,783ctx: ToolContext,784vs_currency: str = "usd",785order: str = "market_cap_desc",786per_page: int = 100,787page: int = 1,788sparkline: bool = False,789price_change_percentage: str = "24h",790category: Optional[str] = None,791ids: Optional[str] = None792) -> ToolResult:793if not COINGECKO_AVAILABLE:794return ToolResult(795success=False,796output=None,797error="CoinGecko tools not available."798)799800try:801result = await asyncio.to_thread(802get_coins_markets,803vs_currency=vs_currency,804order=order,805per_page=per_page,806page=page,807sparkline=sparkline,808price_change_percentage=price_change_percentage,809category=category,810ids=ids811)812return ToolResult(success=True, output=result)813except Exception as e:814return ToolResult(success=False, output=None, error=str(e))815816817class CoinGeckoCoinDataTool(BaseTool):818"""819Get full coin metadata including description, links, ATH, ATL.820"""821822@property823def name(self) -> str:824return "cg_coin_data"825826@property827def description(self) -> str:828return """Get comprehensive coin data including description, links, ATH, ATL, market data.829830Deep research on specific coin.831832Examples:833- Get Bitcoin data: cg_coin_data(coin_id="bitcoin")834- Include tickers: cg_coin_data(coin_id="ethereum", tickers=True)835- Full data: cg_coin_data(coin_id="solana", community_data=True, developer_data=True)"""836837@property838def parameters(self) -> dict:839return {840"type": "object",841"properties": {842"coin_id": {843"type": "string",844"description": "CoinGecko coin ID (bitcoin, ethereum, solana)"845},846"localization": {847"type": "boolean",848"description": "Include localized languages",849"default": False850},851"tickers": {852"type": "boolean",853"description": "Include tickers data",854"default": False855},856"market_data": {857"type": "boolean",858"description": "Include market data",859"default": True860},861"community_data": {862"type": "boolean",863"description": "Include community data",864"default": False865},866"developer_data": {867"type": "boolean",868"description": "Include developer data",869"default": False870},871"sparkline": {872"type": "boolean",873"description": "Include sparkline 7 days data",874"default": False875}876},877"required": ["coin_id"]878}879880async def execute(881self,882ctx: ToolContext,883coin_id: str,884localization: bool = False,885tickers: bool = False,886market_data: bool = True,887community_data: bool = False,888developer_data: bool = False,889sparkline: bool = False890) -> ToolResult:891if not COINGECKO_AVAILABLE:892return ToolResult(893success=False,894output=None,895error="CoinGecko tools not available."896)897898try:899result = await asyncio.to_thread(900get_coin_data,901coin_id=coin_id,902localization=localization,903tickers=tickers,904market_data=market_data,905community_data=community_data,906developer_data=developer_data,907sparkline=sparkline908)909return ToolResult(success=True, output=result)910except Exception as e:911return ToolResult(success=False, output=None, error=str(e))912913914class CoinGeckoCoinTickersTool(BaseTool):915"""916Get all trading pairs/tickers for a coin across exchanges.917"""918919@property920def name(self) -> str:921return "cg_coin_tickers"922923@property924def description(self) -> str:925return """Get all trading pairs/tickers for a coin across exchanges.926927Find liquidity and arbitrage opportunities.928929Examples:930- Get BTC tickers: cg_coin_tickers(coin_id="bitcoin")931- Filter by exchange: cg_coin_tickers(coin_id="ethereum", exchange_ids="binance")932- With depth: cg_coin_tickers(coin_id="solana", depth=True)"""933934@property935def parameters(self) -> dict:936return {937"type": "object",938"properties": {939"coin_id": {940"type": "string",941"description": "CoinGecko coin ID"942},943"exchange_ids": {944"type": "string",945"description": "Comma-separated exchange ids to filter"946},947"include_exchange_logo": {948"type": "boolean",949"description": "Include exchange logo",950"default": False951},952"page": {953"type": "integer",954"description": "Page number",955"default": 1956},957"order": {958"type": "string",959"description": "Sort order: trust_score_desc, volume_desc",960"default": "volume_desc"961},962"depth": {963"type": "boolean",964"description": "Include order book depth",965"default": False966}967},968"required": ["coin_id"]969}970971async def execute(972self,973ctx: ToolContext,974coin_id: str,975exchange_ids: Optional[str] = None,976include_exchange_logo: bool = False,977page: int = 1,978order: str = "volume_desc",979depth: bool = False980) -> ToolResult:981if not COINGECKO_AVAILABLE:982return ToolResult(983success=False,984output=None,985error="CoinGecko tools not available."986)987988try:989result = await asyncio.to_thread(990get_coin_tickers,991coin_id=coin_id,992exchange_ids=exchange_ids,993include_exchange_logo=include_exchange_logo,994page=page,995order=order,996depth=depth997)998return ToolResult(success=True, output=result)999except Exception as e:1000return ToolResult(success=False, output=None, error=str(e))100110021003# ==================== Exchange Tools ====================10041005class CoinGeckoExchangesTool(BaseTool):1006"""1007Get all spot exchanges with volumes and trust scores.1008"""10091010@property1011def name(self) -> str:1012return "cg_exchanges"10131014@property1015def description(self) -> str:1016return """Get all spot exchanges with volumes and trust scores.10171018Compare exchanges by volume and trust.10191020Examples:1021- Get top 100 exchanges: cg_exchanges()1022- Paginate: cg_exchanges(per_page=50, page=2)"""10231024@property1025def parameters(self) -> dict:1026return {1027"type": "object",1028"properties": {1029"per_page": {1030"type": "integer",1031"description": "Results per page (max 250)",1032"default": 1001033},1034"page": {1035"type": "integer",1036"description": "Page number",1037"default": 11038}1039}1040}10411042async def execute(1043self,1044ctx: ToolContext,1045per_page: int = 100,1046page: int = 11047) -> ToolResult:1048if not COINGECKO_AVAILABLE:1049return ToolResult(1050success=False,1051output=None,1052error="CoinGecko tools not available."1053)10541055try:1056result = await asyncio.to_thread(get_exchanges, per_page, page)1057return ToolResult(success=True, output=result)1058except Exception as e:1059return ToolResult(success=False, output=None, error=str(e))106010611062class CoinGeckoExchangeTool(BaseTool):1063"""1064Get detailed exchange data.1065"""10661067@property1068def name(self) -> str:1069return "cg_exchange"10701071@property1072def description(self) -> str:1073return """Get detailed exchange data including tickers and BTC volume.10741075Research specific exchange.10761077Examples:1078- Get Binance data: cg_exchange(exchange_id="binance")1079- Get Coinbase data: cg_exchange(exchange_id="coinbase-exchange")"""10801081@property1082def parameters(self) -> dict:1083return {1084"type": "object",1085"properties": {1086"exchange_id": {1087"type": "string",1088"description": "CoinGecko exchange ID (binance, coinbase-exchange)"1089}1090},1091"required": ["exchange_id"]1092}10931094async def execute(1095self,1096ctx: ToolContext,1097exchange_id: str1098) -> ToolResult:1099if not COINGECKO_AVAILABLE:1100return ToolResult(1101success=False,1102output=None,1103error="CoinGecko tools not available."1104)11051106try:1107result = await asyncio.to_thread(get_exchange, exchange_id)1108return ToolResult(success=True, output=result)1109except Exception as e:1110return ToolResult(success=False, output=None, error=str(e))111111121113class CoinGeckoExchangeTickersTool(BaseTool):1114"""1115Get all trading pairs on an exchange.1116"""11171118@property1119def name(self) -> str:1120return "cg_exchange_tickers"11211122@property1123def description(self) -> str:1124return """Get all trading pairs on an exchange.11251126Find trading opportunities on specific exchange.11271128Examples:1129- Get Binance pairs: cg_exchange_tickers(exchange_id="binance")1130- Filter by coin: cg_exchange_tickers(exchange_id="coinbase-exchange", coin_ids="bitcoin")"""11311132@property1133def parameters(self) -> dict:1134return {1135"type": "object",1136"properties": {1137"exchange_id": {1138"type": "string",1139"description": "CoinGecko exchange ID"1140},1141"coin_ids": {1142"type": "string",1143"description": "Comma-separated coin ids to filter"1144},1145"include_exchange_logo": {1146"type": "boolean",1147"description": "Include exchange logo",1148"default": False1149},1150"page": {1151"type": "integer",1152"description": "Page number",1153"default": 11154},1155"order": {1156"type": "string",1157"description": "Sort order: trust_score_desc, volume_desc",1158"default": "volume_desc"1159},1160"depth": {1161"type": "boolean",1162"description": "Include order book depth",1163"default": False1164}1165},1166"required": ["exchange_id"]1167}11681169async def execute(1170self,1171ctx: ToolContext,1172exchange_id: str,1173coin_ids: Optional[str] = None,1174include_exchange_logo: bool = False,1175page: int = 1,1176order: str = "volume_desc",1177depth: bool = False1178) -> ToolResult:1179if not COINGECKO_AVAILABLE:1180return ToolResult(1181success=False,1182output=None,1183error="CoinGecko tools not available."1184)11851186try:1187result = await asyncio.to_thread(1188get_exchange_tickers,1189exchange_id=exchange_id,1190coin_ids=coin_ids,1191include_exchange_logo=include_exchange_logo,1192page=page,1193order=order,1194depth=depth1195)1196return ToolResult(success=True, output=result)1197except Exception as e:1198return ToolResult(success=False, output=None, error=str(e))119912001201class CoinGeckoExchangeVolumeChartTool(BaseTool):1202"""1203Get historical volume chart for an exchange.1204"""12051206@property1207def name(self) -> str:1208return "cg_exchange_volume_chart"12091210@property1211def description(self) -> str:1212return """Get historical volume chart for an exchange.12131214Track exchange growth over time.12151216Examples:1217- Get Binance 30-day volume: cg_exchange_volume_chart(exchange_id="binance")1218- Get 90-day history: cg_exchange_volume_chart(exchange_id="coinbase-exchange", days=90)"""12191220@property1221def parameters(self) -> dict:1222return {1223"type": "object",1224"properties": {1225"exchange_id": {1226"type": "string",1227"description": "CoinGecko exchange ID"1228},1229"days": {1230"type": "integer",1231"description": "Number of days (1, 7, 14, 30, 90, 180, 365)",1232"default": 301233}1234},1235"required": ["exchange_id"]1236}12371238async def execute(1239self,1240ctx: ToolContext,1241exchange_id: str,1242days: int = 301243) -> ToolResult:1244if not COINGECKO_AVAILABLE:1245return ToolResult(1246success=False,1247output=None,1248error="CoinGecko tools not available."1249)12501251try:1252result = await asyncio.to_thread(get_exchange_volume_chart, exchange_id, days)1253return ToolResult(success=True, output=result)1254except Exception as e:1255return ToolResult(success=False, output=None, error=str(e))125612571258# ==================== NFT Tools ====================12591260class CoinGeckoNFTsListTool(BaseTool):1261"""1262Get all NFT collections.1263"""12641265@property1266def name(self) -> str:1267return "cg_nfts_list"12681269@property1270def description(self) -> str:1271return """Get all NFT collections with IDs and contract addresses.12721273NFT discovery.12741275Examples:1276- Get top NFTs by market cap: cg_nfts_list()1277- Sort by volume: cg_nfts_list(order="h24_volume_usd_desc")"""12781279@property1280def parameters(self) -> dict:1281return {1282"type": "object",1283"properties": {1284"order": {1285"type": "string",1286"description": "Sort order: market_cap_usd_desc, h24_volume_usd_desc",1287"default": "market_cap_usd_desc"1288},1289"per_page": {1290"type": "integer",1291"description": "Results per page (max 250)",1292"default": 1001293},1294"page": {1295"type": "integer",1296"description": "Page number",1297"default": 11298}1299}1300}13011302async def execute(1303self,1304ctx: ToolContext,1305order: str = "market_cap_usd_desc",1306per_page: int = 100,1307page: int = 11308) -> ToolResult:1309if not COINGECKO_AVAILABLE:1310return ToolResult(1311success=False,1312output=None,1313error="CoinGecko tools not available."1314)13151316try:1317result = await asyncio.to_thread(get_nfts_list, order, per_page, page)1318return ToolResult(success=True, output=result)1319except Exception as e:1320return ToolResult(success=False, output=None, error=str(e))132113221323class CoinGeckoNFTTool(BaseTool):1324"""1325Get NFT collection data.1326"""13271328@property1329def name(self) -> str:1330return "cg_nft"13311332@property1333def description(self) -> str:1334return """Get NFT collection data including floor price, volume, market cap.13351336NFT research.13371338Examples:1339- Get Bored Apes: cg_nft(nft_id="bored-ape-yacht-club")1340- Get CryptoPunks: cg_nft(nft_id="cryptopunks")"""13411342@property1343def parameters(self) -> dict:1344return {1345"type": "object",1346"properties": {1347"nft_id": {1348"type": "string",1349"description": "CoinGecko NFT collection ID"1350}1351},1352"required": ["nft_id"]1353}13541355async def execute(1356self,1357ctx: ToolContext,1358nft_id: str1359) -> ToolResult:1360if not COINGECKO_AVAILABLE:1361return ToolResult(1362success=False,1363output=None,1364error="CoinGecko tools not available."1365)13661367try:1368result = await asyncio.to_thread(get_nft, nft_id)1369return ToolResult(success=True, output=result)1370except Exception as e:1371return ToolResult(success=False, output=None, error=str(e))137213731374class CoinGeckoNFTByContractTool(BaseTool):1375"""1376Get NFT collection by contract address.1377"""13781379@property1380def name(self) -> str:1381return "cg_nft_by_contract"13821383@property1384def description(self) -> str:1385return """Get NFT collection by contract address.13861387On-chain NFT lookup.13881389Examples:1390- Get BAYC by contract: cg_nft_by_contract(asset_platform="ethereum", contract_address="0xbc4ca0eda7647a8ab7c2061c2e118a18a936f13d")"""13911392@property1393def parameters(self) -> dict:1394return {1395"type": "object",1396"properties": {1397"asset_platform": {1398"type": "string",1399"description": "Asset platform id (ethereum, solana)"1400},1401"contract_address": {1402"type": "string",1403"description": "NFT contract address"1404}1405},1406"required": ["asset_platform", "contract_address"]1407}14081409async def execute(1410self,1411ctx: ToolContext,1412asset_platform: str,1413contract_address: str1414) -> ToolResult:1415if not COINGECKO_AVAILABLE:1416return ToolResult(1417success=False,1418output=None,1419error="CoinGecko tools not available."1420)14211422try:1423result = await asyncio.to_thread(get_nft_by_contract, asset_platform, contract_address)1424return ToolResult(success=True, output=result)1425except Exception as e:1426return ToolResult(success=False, output=None, error=str(e))142714281429# ==================== Infrastructure Tools ====================14301431class CoinGeckoAssetPlatformsTool(BaseTool):1432"""1433Get all blockchain networks/asset platforms.1434"""14351436@property1437def name(self) -> str:1438return "cg_asset_platforms"14391440@property1441def description(self) -> str:1442return """Get all blockchain networks (Ethereum, Solana, etc.).14431444Filter by chain.14451446Examples:1447- Get all platforms: cg_asset_platforms()1448- Filter NFT platforms: cg_asset_platforms(filter="nft")"""14491450@property1451def parameters(self) -> dict:1452return {1453"type": "object",1454"properties": {1455"filter": {1456"type": "string",1457"description": "Filter platforms (e.g., nft)"1458}1459}1460}14611462async def execute(1463self,1464ctx: ToolContext,1465filter: Optional[str] = None1466) -> ToolResult:1467if not COINGECKO_AVAILABLE:1468return ToolResult(1469success=False,1470output=None,1471error="CoinGecko tools not available."1472)14731474try:1475result = await asyncio.to_thread(get_asset_platforms, filter)1476return ToolResult(success=True, output=result)1477except Exception as e:1478return ToolResult(success=False, output=None, error=str(e))147914801481class CoinGeckoExchangeRatesTool(BaseTool):1482"""1483Get BTC exchange rates to all fiat currencies.1484"""14851486@property1487def name(self) -> str:1488return "cg_exchange_rates"14891490@property1491def description(self) -> str:1492return """Get BTC exchange rates to all fiat currencies.14931494Currency conversion.14951496Examples:1497- Get exchange rates: cg_exchange_rates()"""14981499@property1500def parameters(self) -> dict:1501return {1502"type": "object",1503"properties": {}1504}15051506async def execute(self, ctx: ToolContext) -> ToolResult:1507if not COINGECKO_AVAILABLE:1508return ToolResult(1509success=False,1510output=None,1511error="CoinGecko tools not available."1512)15131514try:1515result = await asyncio.to_thread(get_exchange_rates)1516return ToolResult(success=True, output=result)1517except Exception as e:1518return ToolResult(success=False, output=None, error=str(e))151915201521class CoinGeckoVsCurrenciesTool(BaseTool):1522"""1523Get list of supported quote currencies.1524"""15251526@property1527def name(self) -> str:1528return "cg_vs_currencies"15291530@property1531def description(self) -> str:1532return """Get list of supported quote currencies (vs_currencies).15331534Reference data.15351536Examples:1537- Get supported currencies: cg_vs_currencies()"""15381539@property1540def parameters(self) -> dict:1541return {1542"type": "object",1543"properties": {}1544}15451546async def execute(self, ctx: ToolContext) -> ToolResult:1547if not COINGECKO_AVAILABLE:1548return ToolResult(1549success=False,1550output=None,1551error="CoinGecko tools not available."1552)15531554try:1555result = await asyncio.to_thread(get_vs_currencies)1556return ToolResult(success=True, output=result)1557except Exception as e:1558return ToolResult(success=False, output=None, error=str(e))155915601561class CoinGeckoCategoriesListTool(BaseTool):1562"""1563Get lightweight list of category names and IDs.1564"""15651566@property1567def name(self) -> str:1568return "cg_categories_list"15691570@property1571def description(self) -> str:1572return """Get lightweight list of category names and IDs (no market data).15731574Quick lookup.15751576Examples:1577- Get categories list: cg_categories_list()"""15781579@property1580def parameters(self) -> dict:1581return {1582"type": "object",1583"properties": {}1584}15851586async def execute(self, ctx: ToolContext) -> ToolResult:1587if not COINGECKO_AVAILABLE:1588return ToolResult(1589success=False,1590output=None,1591error="CoinGecko tools not available."1592)15931594try:1595result = await asyncio.to_thread(get_categories_list)1596return ToolResult(success=True, output=result)1597except Exception as e:1598return ToolResult(success=False, output=None, error=str(e))159916001601# ==================== Search Tool ====================16021603class CoinGeckoSearchTool(BaseTool):1604"""1605Search for coins, exchanges, categories, and NFTs.1606"""16071608@property1609def name(self) -> str:1610return "cg_search"16111612@property1613def description(self) -> str:1614return """Search for coins, exchanges, categories, and NFTs.16151616Discovery across all CoinGecko data.16171618Examples:1619- Search for Solana: cg_search(query="solana")1620- Search for DeFi: cg_search(query="defi")"""16211622@property1623def parameters(self) -> dict:1624return {1625"type": "object",1626"properties": {1627"query": {1628"type": "string",1629"description": "Search query"1630}1631},1632"required": ["query"]1633}16341635async def execute(1636self,1637ctx: ToolContext,1638query: str1639) -> ToolResult:1640if not COINGECKO_AVAILABLE:1641return ToolResult(1642success=False,1643output=None,1644error="CoinGecko tools not available."1645)16461647try:1648result = await asyncio.to_thread(search, query)1649return ToolResult(success=True, output=result)1650except Exception as e:1651return ToolResult(success=False, output=None, error=str(e))165216531654# ==================== Contract Tools ====================16551656class CoinGeckoTokenPriceTool(BaseTool):1657"""1658Get token prices by contract address.1659"""16601661@property1662def name(self) -> str:1663return "cg_token_price"16641665@property1666def description(self) -> str:1667return """Get token prices by contract address.16681669On-chain pricing.16701671Examples:1672- Get USDC price on Ethereum: cg_token_price(platform="ethereum", contract_addresses="0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48")1673- Multiple tokens: cg_token_price(platform="ethereum", contract_addresses="0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48,0xdac17f958d2ee523a2206206994597c13d831ec7")"""16741675@property1676def parameters(self) -> dict:1677return {1678"type": "object",1679"properties": {1680"platform": {1681"type": "string",1682"description": "Asset platform id (ethereum, solana, polygon-pos)"1683},1684"contract_addresses": {1685"type": "string",1686"description": "Comma-separated contract addresses"1687},1688"vs_currencies": {1689"type": "string",1690"description": "Comma-separated target currencies (usd, eur, btc)",1691"default": "usd"1692},1693"include_market_cap": {1694"type": "boolean",1695"description": "Include market cap",1696"default": False1697},1698"include_24hr_vol": {1699"type": "boolean",1700"description": "Include 24h volume",1701"default": False1702},1703"include_24hr_change": {1704"type": "boolean",1705"description": "Include 24h price change",1706"default": False1707},1708"include_last_updated_at": {1709"type": "boolean",1710"description": "Include last updated timestamp",1711"default": False1712}1713},1714"required": ["platform", "contract_addresses"]1715}17161717async def execute(1718self,1719ctx: ToolContext,1720platform: str,1721contract_addresses: str,1722vs_currencies: str = "usd",1723include_market_cap: bool = False,1724include_24hr_vol: bool = False,1725include_24hr_change: bool = False,1726include_last_updated_at: bool = False1727) -> ToolResult:1728if not COINGECKO_AVAILABLE:1729return ToolResult(1730success=False,1731output=None,1732error="CoinGecko tools not available."1733)17341735try:1736result = await asyncio.to_thread(1737get_token_price,1738platform=platform,1739contract_addresses=contract_addresses,1740vs_currencies=vs_currencies,1741include_market_cap=include_market_cap,1742include_24hr_vol=include_24hr_vol,1743include_24hr_change=include_24hr_change,1744include_last_updated_at=include_last_updated_at1745)1746return ToolResult(success=True, output=result)1747except Exception as e:1748return ToolResult(success=False, output=None, error=str(e))174917501751class CoinGeckoCoinByContractTool(BaseTool):1752"""1753Get coin data by contract address.1754"""17551756@property1757def name(self) -> str:1758return "cg_coin_by_contract"17591760@property1761def description(self) -> str:1762return """Get coin data by contract address.17631764On-chain lookup.17651766Examples:1767- Get USDC on Ethereum: cg_coin_by_contract(platform="ethereum", contract_address="0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48")"""17681769@property1770def parameters(self) -> dict:1771return {1772"type": "object",1773"properties": {1774"platform": {1775"type": "string",1776"description": "Asset platform id (ethereum, solana, polygon-pos)"1777},1778"contract_address": {1779"type": "string",1780"description": "Token contract address"1781}1782},1783"required": ["platform", "contract_address"]1784}17851786async def execute(1787self,1788ctx: ToolContext,1789platform: str,1790contract_address: str1791) -> ToolResult:1792if not COINGECKO_AVAILABLE:1793return ToolResult(1794success=False,1795output=None,1796error="CoinGecko tools not available."1797)17981799try:1800result = await asyncio.to_thread(get_coin_by_contract, platform, contract_address)1801return ToolResult(success=True, output=result)1802except Exception as e:1803return ToolResult(success=False, output=None, error=str(e))1804