Learn how to fetch market data, token information, and trends using CoinGecko
Solana Agent Kit provides comprehensive integration with CoinGecko’s API for accessing market data, token information, and trending metrics. The integration supports both Pro and Demo API keys with fallback functionality.
// Check for API key availabilityif (!agent.methods.config.COINGECKO_PRO_API_KEY) { // Fallback to demo key if available if (agent.methods.config.COINGECKO_DEMO_API_KEY) { // Use demo endpoints }}
Error Handling
Copy
try { const data = await agent.methods.getTokenPriceData(tokens);} catch (error) { if (error.message.includes("API key")) { // Handle authentication issues } else if (error.message.includes("rate limit")) { // Handle rate limiting }}
Batch Processing
Copy
// Process tokens in batches to avoid URL length limitsconst batchSize = 100;const batches = chunk(tokenAddresses, batchSize);const results = await Promise.all( batches.map(batch => agent.methods.getTokenPriceData(batch)));
const ERROR_MESSAGES = { NO_API_KEY: "No CoinGecko Pro API key provided", RATE_LIMIT: "API rate limit exceeded", INVALID_TOKEN: "Invalid token address", NETWORK_ERROR: "Failed to fetch data from CoinGecko"};