Use CoinGecko
The Use CoinGecko
tool, part of AgentiPy, allows users to fetch various cryptocurrency market data from CoinGecko's API. This includes trending tokens, trending liquidity pools on Solana, top gainer/loser tokens, token price information, and detailed token info. Some endpoints are free, while others require a CoinGecko Pro API key.
Functionality
This tool is implemented in the CoingeckoManager
class.
Key Methods:
get_trending_tokens(agent: SolanaAgentKit) -> dict
:Fetches trending search terms/tokens on CoinGecko. Uses a free CoinGecko endpoint.
Can optionally use a demo API key if provided in
agent.coingecko_demo_api_key
and no pro key is set.
get_trending_pools(agent: SolanaAgentKit, duration: str = "24h") -> dict
:Fetches trending liquidity pools on the Solana network.
Requires a CoinGecko Pro API key set in
agent.coingecko_api_key
.duration
can be "5m", "1h", "6h", "24h".
get_top_gainers(agent: SolanaAgentKit, duration: str = "24h", top_coins: int | str = "all") -> dict
:Fetches top gainer (and loser) tokens.
Requires a CoinGecko Pro API key.
duration
can be "1h", "24h", "7d", etc.top_coins
can be 300, 500, 1000, or "all".
get_token_price_data(agent: SolanaAgentKit, token_addresses: list[str]) -> dict
:Fetches price data for a list of Solana token contract addresses (e.g., USD price, market cap, 24h volume, 24h change). Uses a free CoinGecko endpoint.
Can optionally use a demo API key.
get_token_info(agent: SolanaAgentKit, token_address: str) -> dict
:Fetches detailed information for a specific Solana token contract address.
Requires a CoinGecko Pro API key.
get_latest_pools(agent: SolanaAgentKit) -> dict
:Fetches the latest liquidity pools created on the Solana network.
Requires a CoinGecko Pro API key.
CoinGecko Manager Tool
The CoingeckoManager
class (located in agentipy/tools/use_coingecko.py
) serves as your interface for fetching a variety of market data from the CoinGecko API. This data is invaluable for AI agents requiring up-to-date information on token prices, market trends, and new opportunities on supported networks like Solana.
Purpose: To provide easy and structured access to CoinGecko's comprehensive market data API, enabling AI agents to make informed decisions based on real-time and historical cryptocurrency metrics.
Under the Hood:
The CoingeckoManager
methods make asynchronous HTTP requests to the official CoinGecko API endpoints (both free public endpoints and professional API endpoints). It parses the JSON responses and returns the data as Python dictionaries.
API Keys:
Access to most of the powerful methods within this tool, especially those fetching detailed or real-time data like trending pools, top gainers, latest pools, and detailed token info, requires a CoinGecko Pro API key. Some basic methods (like get_trending_tokens
and get_token_price_data
) might work with a CoinGecko Demo API key or the standard free API tier, but these are subject to much stricter rate limits and may not be suitable for frequent querying by an agent.
It is highly recommended to obtain a CoinGecko Pro API key for reliable and extensive market data access. You must provide your CoinGecko API keys (both Pro and Demo, if you have them) when initializing your SolanaAgentKit
instance, as the CoingeckoManager
methods access them via the passed agent
object:
import os # Recommended for secure key loading
from solders.keypair import Keypair # Assuming you load your keypair securely
from agentipy.agent import SolanaAgentKit
# Example: Securely load your wallet keypair (replace with your actual method)
# wallet_keypair = Keypair.from_bytes(base58.b58decode(os.environ.get("SOLANA_PRIVATE_KEY")))
agent = SolanaAgentKit(
wallet_keypair=wallet_keypair, # Your loaded Keypair
rpc_url="YOUR_SOLANA_RPC_URL", # Your Solana RPC endpoint
# Add your CoinGecko API keys here:
coingecko_api_key=os.environ.get("COINGECKO_PRO_API_KEY"), # <--- Your PRO key (recommended)
coingecko_demo_api_key=os.environ.get("COINGECKO_DEMO_API_KEY") # <--- Your DEMO key (optional fallback)
)
The agent instance is a required parameter for all CoingeckoManager methods so they can access these configured API keys and potentially other agent settings.
Source Code
You can find the source code for this tool on GitHub: https://github.com/niceberginc/agentipy/blob/main/agentipy/tools/use_coingecko.py
Last updated