coingecko
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseCoinGecko Solana API Development Guide
CoinGecko Solana API 开发指南
A comprehensive guide for integrating CoinGecko's on-chain API for Solana. Access real-time token prices, DEX pool data, OHLCV charts, trade history, and market analytics across 1,700+ decentralized exchanges.
本指南全面介绍如何集成CoinGecko的Solana链上API,可获取1700+去中心化交易所的实时代币价格、DEX流动性池数据、OHLCV图表、交易历史及市场分析数据。
Overview
概述
CoinGecko's Solana API provides:
- Token Prices: Real-time prices by contract address (single or batch)
- Pool Data: Liquidity pool information, trending pools, top pools
- OHLCV Charts: Candlestick data for technical analysis
- Trade History: Recent trades for any pool
- DEX Discovery: List all DEXes operating on Solana
- Search: Find pools by token name, symbol, or address
- Megafilter: Advanced filtering across pools, tokens, and DEXes
CoinGecko Solana API提供以下功能:
- 代币价格:通过合约地址获取实时价格(单地址或批量查询)
- 流动性池数据:流动性池信息、热门池、顶级池数据
- OHLCV图表:用于技术分析的K线数据
- 交易历史:任意流动性池的近期交易记录
- DEX发现:列出Solana链上所有去中心化交易所
- 搜索功能:通过代币名称、符号或地址查找流动性池
- 高级筛选:对流动性池、代币及DEX进行多维度高级筛选
Key Features
核心特性
| Feature | Description |
|---|---|
| 250+ Networks | Multi-chain support including Solana |
| 1,700+ DEXes | Raydium, Orca, Jupiter, Meteora, Pump.fun, etc. |
| 15M+ Tokens | Comprehensive token coverage |
| Real-time Data | Updates every 10-30 seconds |
| Historical Data | OHLCV charts and trade history |
| 特性 | 描述 |
|---|---|
| 250+ 网络 | 支持多链,包括Solana |
| 1700+ DEX | 覆盖Raydium、Orca、Jupiter、Meteora、Pump.fun等平台 |
| 1500万+ 代币 | 全面的代币覆盖范围 |
| 实时数据 | 每10-30秒更新一次 |
| 历史数据 | 提供OHLCV图表及交易历史数据 |
Quick Start
快速开始
Get Your API Key
获取API密钥
- Demo API (Free): Visit coingecko.com/en/api
- Pro API (Paid): Visit coingecko.com/en/api/pricing
- 演示API(免费):访问 coingecko.com/en/api
- 专业API(付费):访问 coingecko.com/en/api/pricing
Environment Setup
环境配置
bash
undefinedbash
undefined.env file
.env 文件
COINGECKO_API_KEY=your_api_key_here
COINGECKO_API_TYPE=demo # or 'pro'
undefinedCOINGECKO_API_KEY=your_api_key_here
COINGECKO_API_TYPE=demo # 或 'pro'
undefinedAPI Configuration
API配置
typescript
// Configuration for both Demo and Pro APIs
const CONFIG = {
demo: {
baseUrl: 'https://api.coingecko.com/api/v3/onchain',
headerKey: 'x-cg-demo-api-key',
rateLimit: 30, // calls per minute
},
pro: {
baseUrl: 'https://pro-api.coingecko.com/api/v3/onchain',
headerKey: 'x-cg-pro-api-key',
rateLimit: 500, // calls per minute (varies by plan)
},
};
const apiType = process.env.COINGECKO_API_TYPE || 'demo';
const apiKey = process.env.COINGECKO_API_KEY;
const BASE_URL = CONFIG[apiType].baseUrl;
const HEADER_KEY = CONFIG[apiType].headerKey;
// Solana network identifier
const NETWORK = 'solana';typescript
// 同时适用于演示版和专业版API的配置
const CONFIG = {
demo: {
baseUrl: 'https://api.coingecko.com/api/v3/onchain',
headerKey: 'x-cg-demo-api-key',
rateLimit: 30, // 每分钟调用次数
},
pro: {
baseUrl: 'https://pro-api.coingecko.com/api/v3/onchain',
headerKey: 'x-cg-pro-api-key',
rateLimit: 500, // 每分钟调用次数(根据套餐不同有所差异)
},
};
const apiType = process.env.COINGECKO_API_TYPE || 'demo';
const apiKey = process.env.COINGECKO_API_KEY;
const BASE_URL = CONFIG[apiType].baseUrl;
const HEADER_KEY = CONFIG[apiType].headerKey;
// Solana网络标识符
const NETWORK = 'solana';Basic Token Price Fetch
基础代币价格获取
typescript
async function getTokenPrice(tokenAddress: string): Promise<number | null> {
const url = `${BASE_URL}/simple/networks/${NETWORK}/token_price/${tokenAddress}`;
const response = await fetch(url, {
headers: {
[HEADER_KEY]: apiKey,
'Accept': 'application/json',
},
});
if (!response.ok) {
throw new Error(`API error: ${response.status}`);
}
const data = await response.json();
return data.data?.attributes?.token_prices?.[tokenAddress] ?? null;
}
// Usage
const USDC = 'EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v';
const price = await getTokenPrice(USDC);
console.log(`USDC Price: $${price}`);typescript
async function getTokenPrice(tokenAddress: string): Promise<number | null> {
const url = `${BASE_URL}/simple/networks/${NETWORK}/token_price/${tokenAddress}`;
const response = await fetch(url, {
headers: {
[HEADER_KEY]: apiKey,
'Accept': 'application/json',
},
});
if (!response.ok) {
throw new Error(`API错误: ${response.status}`);
}
const data = await response.json();
return data.data?.attributes?.token_prices?.[tokenAddress] ?? null;
}
// 使用示例
const USDC = 'EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v';
const price = await getTokenPrice(USDC);
console.log(`USDC价格: $${price}`);API Endpoints Reference
API端点参考
Simple Token Price
简单代币价格查询
Get token prices by contract address.
Endpoint:
GET /simple/networks/{network}/token_price/{addresses}Parameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
| string | Yes | Network ID ( |
| string | Yes | Comma-separated token addresses (max 30 Demo, 100 Pro) |
| boolean | No | Include market cap data |
| boolean | No | Include 24h volume |
| boolean | No | Include 24h price change % |
typescript
async function getTokenPrices(addresses: string[]): Promise<Record<string, TokenPriceData>> {
const addressList = addresses.join(',');
const url = `${BASE_URL}/simple/networks/${NETWORK}/token_price/${addressList}`;
const params = new URLSearchParams({
include_market_cap: 'true',
include_24hr_vol: 'true',
include_24hr_price_change: 'true',
});
const response = await fetch(`${url}?${params}`, {
headers: { [HEADER_KEY]: apiKey },
});
const data = await response.json();
return data.data?.attributes || {};
}通过合约地址获取代币价格。
端点:
GET /simple/networks/{network}/token_price/{addresses}参数:
| 参数 | 类型 | 是否必填 | 描述 |
|---|---|---|---|
| string | 是 | 网络ID( |
| string | 是 | 逗号分隔的代币地址(演示版最多30个,专业版最多100个) |
| boolean | 否 | 是否包含市值数据 |
| boolean | 否 | 是否包含24小时交易量 |
| boolean | 否 | 是否包含24小时价格变动百分比 |
typescript
async function getTokenPrices(addresses: string[]): Promise<Record<string, TokenPriceData>> {
const addressList = addresses.join(',');
const url = `${BASE_URL}/simple/networks/${NETWORK}/token_price/${addressList}`;
const params = new URLSearchParams({
include_market_cap: 'true',
include_24hr_vol: 'true',
include_24hr_price_change: 'true',
});
const response = await fetch(`${url}?${params}`, {
headers: { [HEADER_KEY]: apiKey },
});
const data = await response.json();
return data.data?.attributes || {};
}Token Data by Address
通过地址获取代币详情
Get detailed token information.
Endpoint:
GET /networks/{network}/tokens/{address}Parameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
| string | Yes | Network ID |
| string | Yes | Token contract address |
| string | No | Include |
typescript
interface TokenData {
address: string;
name: string;
symbol: string;
decimals: number;
image_url: string;
price_usd: string;
fdv_usd: string;
market_cap_usd: string;
total_supply: string;
volume_usd: {
h24: string;
};
price_change_percentage: {
h24: string;
};
}
async function getTokenData(address: string): Promise<TokenData> {
const url = `${BASE_URL}/networks/${NETWORK}/tokens/${address}?include=top_pools`;
const response = await fetch(url, {
headers: { [HEADER_KEY]: apiKey },
});
const data = await response.json();
return data.data?.attributes;
}获取代币的详细信息。
端点:
GET /networks/{network}/tokens/{address}参数:
| 参数 | 类型 | 是否必填 | 描述 |
|---|---|---|---|
| string | 是 | 网络ID |
| string | 是 | 代币合约地址 |
| string | 否 | 可指定 |
typescript
interface TokenData {
address: string;
name: string;
symbol: string;
decimals: number;
image_url: string;
price_usd: string;
fdv_usd: string;
market_cap_usd: string;
total_supply: string;
volume_usd: {
h24: string;
};
price_change_percentage: {
h24: string;
};
}
async function getTokenData(address: string): Promise<TokenData> {
const url = `${BASE_URL}/networks/${NETWORK}/tokens/${address}?include=top_pools`;
const response = await fetch(url, {
headers: { [HEADER_KEY]: apiKey },
});
const data = await response.json();
return data.data?.attributes;
}Multi-Token Data
批量获取代币数据
Batch fetch multiple tokens.
Endpoint:
GET /networks/{network}/tokens/multi/{addresses}typescript
async function getMultipleTokens(addresses: string[]): Promise<TokenData[]> {
const addressList = addresses.join(',');
const url = `${BASE_URL}/networks/${NETWORK}/tokens/multi/${addressList}`;
const response = await fetch(url, {
headers: { [HEADER_KEY]: apiKey },
});
const data = await response.json();
return data.data?.map((item: any) => item.attributes) || [];
}批量查询多个代币信息。
端点:
GET /networks/{network}/tokens/multi/{addresses}typescript
async function getMultipleTokens(addresses: string[]): Promise<TokenData[]> {
const addressList = addresses.join(',');
const url = `${BASE_URL}/networks/${NETWORK}/tokens/multi/${addressList}`;
const response = await fetch(url, {
headers: { [HEADER_KEY]: apiKey },
});
const data = await response.json();
return data.data?.map((item: any) => item.attributes) || [];
}Pool Data by Address
通过地址获取流动性池数据
Get detailed pool information.
Endpoint:
GET /networks/{network}/pools/{address}Parameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
| string | No | |
| boolean | No | Volume breakdown by timeframe |
typescript
interface PoolData {
address: string;
name: string;
pool_created_at: string;
base_token_price_usd: string;
quote_token_price_usd: string;
base_token_price_native_currency: string;
fdv_usd: string;
market_cap_usd: string;
reserve_in_usd: string;
price_change_percentage: {
m5: string;
h1: string;
h6: string;
h24: string;
};
transactions: {
m5: { buys: number; sells: number };
h1: { buys: number; sells: number };
h24: { buys: number; sells: number };
};
volume_usd: {
m5: string;
h1: string;
h6: string;
h24: string;
};
}
async function getPoolData(poolAddress: string): Promise<PoolData> {
const url = `${BASE_URL}/networks/${NETWORK}/pools/${poolAddress}`;
const params = new URLSearchParams({
include: 'base_token,quote_token,dex',
});
const response = await fetch(`${url}?${params}`, {
headers: { [HEADER_KEY]: apiKey },
});
const data = await response.json();
return data.data?.attributes;
}获取流动性池的详细信息。
端点:
GET /networks/{network}/pools/{address}参数:
| 参数 | 类型 | 是否必填 | 描述 |
|---|---|---|---|
| string | 否 | 可指定 |
| boolean | 否 | 是否按时间范围拆分交易量数据 |
typescript
interface PoolData {
address: string;
name: string;
pool_created_at: string;
base_token_price_usd: string;
quote_token_price_usd: string;
base_token_price_native_currency: string;
fdv_usd: string;
market_cap_usd: string;
reserve_in_usd: string;
price_change_percentage: {
m5: string;
h1: string;
h6: string;
h24: string;
};
transactions: {
m5: { buys: number; sells: number };
h1: { buys: number; sells: number };
h24: { buys: number; sells: number };
};
volume_usd: {
m5: string;
h1: string;
h6: string;
h24: string;
};
}
async function getPoolData(poolAddress: string): Promise<PoolData> {
const url = `${BASE_URL}/networks/${NETWORK}/pools/${poolAddress}`;
const params = new URLSearchParams({
include: 'base_token,quote_token,dex',
});
const response = await fetch(`${url}?${params}`, {
headers: { [HEADER_KEY]: apiKey },
});
const data = await response.json();
return data.data?.attributes;
}Trending Pools
热门流动性池
Get trending pools across all networks or filtered by network.
Endpoint:
GET /networks/trending_poolsParameters:
| Parameter | Type | Default | Description |
|---|---|---|---|
| string | | Attributes to include |
| integer | 1 | Page number |
| string | | |
typescript
async function getTrendingPools(duration: '5m' | '1h' | '6h' | '24h' = '24h'): Promise<PoolData[]> {
const url = `${BASE_URL}/networks/trending_pools`;
const params = new URLSearchParams({
include: 'base_token,quote_token,dex,network',
duration,
page: '1',
});
const response = await fetch(`${url}?${params}`, {
headers: { [HEADER_KEY]: apiKey },
});
const data = await response.json();
return data.data?.map((item: any) => item.attributes) || [];
}
// Filter for Solana pools
async function getSolanaTrendingPools(): Promise<PoolData[]> {
const allPools = await getTrendingPools();
return allPools.filter(pool => pool.network === 'solana');
}获取全网络或指定网络的热门流动性池。
端点:
GET /networks/trending_pools参数:
| 参数 | 类型 | 默认值 | 描述 |
|---|---|---|---|
| string | | 需要包含的属性 |
| integer | 1 | 页码 |
| string | | 时间范围: |
typescript
async function getTrendingPools(duration: '5m' | '1h' | '6h' | '24h' = '24h'): Promise<PoolData[]> {
const url = `${BASE_URL}/networks/trending_pools`;
const params = new URLSearchParams({
include: 'base_token,quote_token,dex,network',
duration,
page: '1',
});
const response = await fetch(`${url}?${params}`, {
headers: { [HEADER_KEY]: apiKey },
});
const data = await response.json();
return data.data?.map((item: any) => item.attributes) || [];
}
// 筛选Solana链上的热门池
async function getSolanaTrendingPools(): Promise<PoolData[]> {
const allPools = await getTrendingPools();
return allPools.filter(pool => pool.network === 'solana');
}Top Pools on Network
网络顶级流动性池
Get top pools by volume on Solana.
Endpoint:
GET /networks/{network}/poolstypescript
async function getTopPools(page: number = 1): Promise<PoolData[]> {
const url = `${BASE_URL}/networks/${NETWORK}/pools`;
const params = new URLSearchParams({
include: 'base_token,quote_token,dex',
page: page.toString(),
});
const response = await fetch(`${url}?${params}`, {
headers: { [HEADER_KEY]: apiKey },
});
const data = await response.json();
return data.data?.map((item: any) => item.attributes) || [];
}获取Solana链上按交易量排名的顶级流动性池。
端点:
GET /networks/{network}/poolstypescript
async function getTopPools(page: number = 1): Promise<PoolData[]> {
const url = `${BASE_URL}/networks/${NETWORK}/pools`;
const params = new URLSearchParams({
include: 'base_token,quote_token,dex',
page: page.toString(),
});
const response = await fetch(`${url}?${params}`, {
headers: { [HEADER_KEY]: apiKey },
});
const data = await response.json();
return data.data?.map((item: any) => item.attributes) || [];
}Search Pools
搜索流动性池
Search for pools by token name, symbol, or address.
Endpoint:
GET /search/poolsParameters:
| Parameter | Type | Description |
|---|---|---|
| string | Search term (name, symbol, address) |
| string | Filter by network |
| integer | Page number |
typescript
async function searchPools(query: string): Promise<PoolData[]> {
const url = `${BASE_URL}/search/pools`;
const params = new URLSearchParams({
query,
network: NETWORK,
include: 'base_token,quote_token,dex',
});
const response = await fetch(`${url}?${params}`, {
headers: { [HEADER_KEY]: apiKey },
});
const data = await response.json();
return data.data?.map((item: any) => item.attributes) || [];
}
// Search for SOL pools
const solPools = await searchPools('SOL');通过代币名称、符号或地址搜索流动性池。
端点:
GET /search/pools参数:
| 参数 | 类型 | 描述 |
|---|---|---|
| string | 搜索关键词(名称、符号、地址) |
| string | 按网络筛选 |
| integer | 页码 |
typescript
async function searchPools(query: string): Promise<PoolData[]> {
const url = `${BASE_URL}/search/pools`;
const params = new URLSearchParams({
query,
network: NETWORK,
include: 'base_token,quote_token,dex',
});
const response = await fetch(`${url}?${params}`, {
headers: { [HEADER_KEY]: apiKey },
});
const data = await response.json();
return data.data?.map((item: any) => item.attributes) || [];
}
// 搜索SOL相关的流动性池
const solPools = await searchPools('SOL');Pool OHLCV Chart
流动性池OHLCV图表
Get candlestick data for technical analysis.
Endpoint:
GET /networks/{network}/pools/{pool_address}/ohlcv/{timeframe}Timeframes: , ,
dayhourminuteParameters:
| Parameter | Type | Description |
|---|---|---|
| integer | Candle aggregation (1, 5, 15 for minute; 1, 4, 12 for hour) |
| integer | Unix timestamp for pagination |
| integer | Number of candles (max 1000) |
| string | |
typescript
interface OHLCVData {
timestamp: number;
open: number;
high: number;
low: number;
close: number;
volume: number;
}
async function getPoolOHLCV(
poolAddress: string,
timeframe: 'day' | 'hour' | 'minute' = 'hour',
aggregate: number = 1,
limit: number = 100
): Promise<OHLCVData[]> {
const url = `${BASE_URL}/networks/${NETWORK}/pools/${poolAddress}/ohlcv/${timeframe}`;
const params = new URLSearchParams({
aggregate: aggregate.toString(),
limit: limit.toString(),
currency: 'usd',
});
const response = await fetch(`${url}?${params}`, {
headers: { [HEADER_KEY]: apiKey },
});
const data = await response.json();
return data.data?.attributes?.ohlcv_list?.map((candle: number[]) => ({
timestamp: candle[0],
open: candle[1],
high: candle[2],
low: candle[3],
close: candle[4],
volume: candle[5],
})) || [];
}
// Get hourly candles
const hourlyCandles = await getPoolOHLCV(poolAddress, 'hour', 1, 24);
// Get 5-minute candles
const fiveMinCandles = await getPoolOHLCV(poolAddress, 'minute', 5, 100);获取用于技术分析的K线数据。
端点:
GET /networks/{network}/pools/{pool_address}/ohlcv/{timeframe}时间范围: , ,
dayhourminute参数:
| 参数 | 类型 | 描述 |
|---|---|---|
| integer | K线聚合周期(分钟线可选1、5、15;小时线可选1、4、12) |
| integer | 分页用的Unix时间戳 |
| integer | K线数量上限(最多1000条) |
| string | 计价单位: |
typescript
interface OHLCVData {
timestamp: number;
open: number;
high: number;
low: number;
close: number;
volume: number;
}
async function getPoolOHLCV(
poolAddress: string,
timeframe: 'day' | 'hour' | 'minute' = 'hour',
aggregate: number = 1,
limit: number = 100
): Promise<OHLCVData[]> {
const url = `${BASE_URL}/networks/${NETWORK}/pools/${poolAddress}/ohlcv/${timeframe}`;
const params = new URLSearchParams({
aggregate: aggregate.toString(),
limit: limit.toString(),
currency: 'usd',
});
const response = await fetch(`${url}?${params}`, {
headers: { [HEADER_KEY]: apiKey },
});
const data = await response.json();
return data.data?.attributes?.ohlcv_list?.map((candle: number[]) => ({
timestamp: candle[0],
open: candle[1],
high: candle[2],
low: candle[3],
close: candle[4],
volume: candle[5],
})) || [];
}
// 获取小时线K线数据
const hourlyCandles = await getPoolOHLCV(poolAddress, 'hour', 1, 24);
// 获取5分钟线K线数据
const fiveMinCandles = await getPoolOHLCV(poolAddress, 'minute', 5, 100);Recent Trades
近期交易记录
Get recent trades for a pool.
Endpoint:
GET /networks/{network}/pools/{pool_address}/tradestypescript
interface TradeData {
block_number: number;
block_timestamp: string;
tx_hash: string;
tx_from_address: string;
from_token_amount: string;
to_token_amount: string;
price_from_in_currency_token: string;
price_to_in_currency_token: string;
price_from_in_usd: string;
price_to_in_usd: string;
kind: 'buy' | 'sell';
volume_in_usd: string;
}
async function getRecentTrades(poolAddress: string): Promise<TradeData[]> {
const url = `${BASE_URL}/networks/${NETWORK}/pools/${poolAddress}/trades`;
const response = await fetch(url, {
headers: { [HEADER_KEY]: apiKey },
});
const data = await response.json();
return data.data?.map((item: any) => item.attributes) || [];
}获取流动性池的近期交易记录。
端点:
GET /networks/{network}/pools/{pool_address}/tradestypescript
interface TradeData {
block_number: number;
block_timestamp: string;
tx_hash: string;
tx_from_address: string;
from_token_amount: string;
to_token_amount: string;
price_from_in_currency_token: string;
price_to_in_currency_token: string;
price_from_in_usd: string;
price_to_in_usd: string;
kind: 'buy' | 'sell';
volume_in_usd: string;
}
async function getRecentTrades(poolAddress: string): Promise<TradeData[]> {
const url = `${BASE_URL}/networks/${NETWORK}/pools/${poolAddress}/trades`;
const response = await fetch(url, {
headers: { [HEADER_KEY]: apiKey },
});
const data = await response.json();
return data.data?.map((item: any) => item.attributes) || [];
}List DEXes on Solana
列出Solana链上的DEX
Get all decentralized exchanges on Solana.
Endpoint:
GET /networks/{network}/dexestypescript
interface DexData {
id: string;
name: string;
}
async function getSolanaDexes(): Promise<DexData[]> {
const url = `${BASE_URL}/networks/${NETWORK}/dexes`;
const response = await fetch(url, {
headers: { [HEADER_KEY]: apiKey },
});
const data = await response.json();
return data.data?.map((item: any) => ({
id: item.id,
name: item.attributes.name,
})) || [];
}获取Solana链上所有去中心化交易所。
端点:
GET /networks/{network}/dexestypescript
interface DexData {
id: string;
name: string;
}
async function getSolanaDexes(): Promise<DexData[]> {
const url = `${BASE_URL}/networks/${NETWORK}/dexes`;
const response = await fetch(url, {
headers: { [HEADER_KEY]: apiKey },
});
const data = await response.json();
return data.data?.map((item: any) => ({
id: item.id,
name: item.attributes.name,
})) || [];
}Megafilter (Advanced)
高级筛选(Megafilter)
Advanced filtering for pools across networks, DEXes, and tokens.
Endpoint:
GET /pools/megafilterParameters:
| Parameter | Type | Description |
|---|---|---|
| string | Filter by network(s) |
| string | Filter by DEX(es) |
| string | Sort order (e.g., |
| number | Minimum liquidity |
| number | Minimum 24h volume |
typescript
async function getMegafilterPools(options: {
dexes?: string[];
minLiquidity?: number;
minVolume?: number;
sort?: string;
}): Promise<PoolData[]> {
const url = `${BASE_URL}/pools/megafilter`;
const params = new URLSearchParams({
networks: NETWORK,
page: '1',
});
if (options.dexes) {
params.set('dexes', options.dexes.join(','));
}
if (options.minLiquidity) {
params.set('min_reserve_in_usd', options.minLiquidity.toString());
}
if (options.minVolume) {
params.set('min_h24_volume_usd', options.minVolume.toString());
}
if (options.sort) {
params.set('sort', options.sort);
}
const response = await fetch(`${url}?${params}`, {
headers: { [HEADER_KEY]: apiKey },
});
const data = await response.json();
return data.data?.map((item: any) => item.attributes) || [];
}
// Get newest Pump.fun pools
const pumpfunPools = await getMegafilterPools({
dexes: ['pump-fun'],
sort: 'pool_created_at_desc',
});
// Get high-volume Raydium pools
const raydiumPools = await getMegafilterPools({
dexes: ['raydium'],
minVolume: 100000,
minLiquidity: 50000,
});对跨网络、跨DEX、跨代币的流动性池进行高级筛选。
端点:
GET /pools/megafilter参数:
| 参数 | 类型 | 描述 |
|---|---|---|
| string | 按网络筛选 |
| string | 按DEX筛选 |
| string | 排序方式(如 |
| number | 最低流动性要求 |
| number | 最低24小时交易量要求 |
typescript
async function getMegafilterPools(options: {
dexes?: string[];
minLiquidity?: number;
minVolume?: number;
sort?: string;
}): Promise<PoolData[]> {
const url = `${BASE_URL}/pools/megafilter`;
const params = new URLSearchParams({
networks: NETWORK,
page: '1',
});
if (options.dexes) {
params.set('dexes', options.dexes.join(','));
}
if (options.minLiquidity) {
params.set('min_reserve_in_usd', options.minLiquidity.toString());
}
if (options.minVolume) {
params.set('min_h24_volume_usd', options.minVolume.toString());
}
if (options.sort) {
params.set('sort', options.sort);
}
const response = await fetch(`${url}?${params}`, {
headers: { [HEADER_KEY]: apiKey },
});
const data = await response.json();
return data.data?.map((item: any) => item.attributes) || [];
}
// 获取最新的Pump.fun流动性池
const pumpfunPools = await getMegafilterPools({
dexes: ['pump-fun'],
sort: 'pool_created_at_desc',
});
// 获取高交易量的Raydium流动性池
const raydiumPools = await getMegafilterPools({
dexes: ['raydium'],
minVolume: 100000,
minLiquidity: 50000,
});Common Solana DEX Identifiers
Solana常见DEX标识符
| DEX | ID | Description |
|---|---|---|
| Raydium | | Leading AMM on Solana |
| Orca | | User-friendly DEX |
| Jupiter | | Aggregator with pools |
| Meteora | | Dynamic AMM |
| Pump.fun | | Memecoin launchpad |
| OpenBook | | Order book DEX |
| Lifinity | | Proactive market maker |
| Phoenix | | On-chain order book |
| DEX | ID | 描述 |
|---|---|---|
| Raydium | | Solana链上领先的自动做市商 |
| Orca | | 用户友好型DEX |
| Jupiter | | 集成流动性池的聚合器 |
| Meteora | | 动态自动做市商 |
| Pump.fun | | 模因币launchpad |
| OpenBook | | 订单簿型DEX |
| Lifinity | | 主动做市商 |
| Phoenix | | 链上订单簿平台 |
Common Token Addresses
常见代币地址
| Token | Address |
|---|---|
| USDC | |
| USDT | |
| SOL (Wrapped) | |
| JUP | |
| BONK | |
| WIF | |
| PYTH | |
| RAY | |
| ORCA | |
| 代币 | 地址 |
|---|---|
| USDC | |
| USDT | |
| SOL(封装版) | |
| JUP | |
| BONK | |
| WIF | |
| PYTH | |
| RAY | |
| ORCA | |
Rate Limits
调用频率限制
| Plan | Calls/Minute | Max Addresses/Request |
|---|---|---|
| Demo (Free) | 30 | 30 |
| Analyst | 500 | 50 |
| Lite | 500 | 50 |
| Pro | 1,000 | 100 |
| Enterprise | Custom | Custom |
| 套餐 | 每分钟调用次数 | 单次请求最大地址数 |
|---|---|---|
| 演示版(免费) | 30 | 30 |
| Analyst | 500 | 50 |
| Lite | 500 | 50 |
| Pro | 1000 | 100 |
| 企业版 | 定制 | 定制 |
Rate Limit Handling
调用频率限制处理
typescript
class RateLimiter {
private calls: number[] = [];
private maxCalls: number;
private windowMs: number = 60000; // 1 minute
constructor(maxCallsPerMinute: number) {
this.maxCalls = maxCallsPerMinute;
}
async waitForSlot(): Promise<void> {
const now = Date.now();
this.calls = this.calls.filter(t => now - t < this.windowMs);
if (this.calls.length >= this.maxCalls) {
const oldestCall = this.calls[0];
const waitTime = this.windowMs - (now - oldestCall);
await new Promise(resolve => setTimeout(resolve, waitTime));
}
this.calls.push(Date.now());
}
}
// Usage
const rateLimiter = new RateLimiter(30); // Demo API
async function fetchWithRateLimit(url: string): Promise<any> {
await rateLimiter.waitForSlot();
const response = await fetch(url, {
headers: { [HEADER_KEY]: apiKey },
});
return response.json();
}typescript
class RateLimiter {
private calls: number[] = [];
private maxCalls: number;
private windowMs: number = 60000; // 1分钟
constructor(maxCallsPerMinute: number) {
this.maxCalls = maxCallsPerMinute;
}
async waitForSlot(): Promise<void> {
const now = Date.now();
this.calls = this.calls.filter(t => now - t < this.windowMs);
if (this.calls.length >= this.maxCalls) {
const oldestCall = this.calls[0];
const waitTime = this.windowMs - (now - oldestCall);
await new Promise(resolve => setTimeout(resolve, waitTime));
}
this.calls.push(Date.now());
}
}
// 使用示例
const rateLimiter = new RateLimiter(30); // 演示版API
async function fetchWithRateLimit(url: string): Promise<any> {
await rateLimiter.waitForSlot();
const response = await fetch(url, {
headers: { [HEADER_KEY]: apiKey },
});
return response.json();
}Error Handling
错误处理
typescript
async function safeApiCall<T>(url: string): Promise<T | null> {
try {
const response = await fetch(url, {
headers: { [HEADER_KEY]: apiKey },
});
if (response.status === 401) {
throw new Error('Invalid API key');
}
if (response.status === 429) {
throw new Error('Rate limit exceeded - wait before retrying');
}
if (response.status === 404) {
console.warn('Resource not found');
return null;
}
if (!response.ok) {
throw new Error(`API error: ${response.status}`);
}
return response.json();
} catch (error) {
console.error('CoinGecko API error:', error);
throw error;
}
}typescript
async function safeApiCall<T>(url: string): Promise<T | null> {
try {
const response = await fetch(url, {
headers: { [HEADER_KEY]: apiKey },
});
if (response.status === 401) {
throw new Error('无效的API密钥');
}
if (response.status === 429) {
throw new Error('调用频率超限,请稍后重试');
}
if (response.status === 404) {
console.warn('资源不存在');
return null;
}
if (!response.ok) {
throw new Error(`API错误: ${response.status}`);
}
return response.json();
} catch (error) {
console.error('CoinGecko API错误:', error);
throw error;
}
}Common Error Codes
常见错误码
| Code | Meaning | Solution |
|---|---|---|
| 401 | Invalid API key | Check your API key |
| 429 | Rate limit exceeded | Wait and retry, or upgrade plan |
| 404 | Resource not found | Check address/network ID |
| 500+ | Server error | Retry with exponential backoff |
| 错误码 | 含义 | 解决方案 |
|---|---|---|
| 401 | 无效的API密钥 | 检查你的API密钥 |
| 429 | 调用频率超限 | 等待后重试,或升级套餐 |
| 404 | 资源不存在 | 检查地址或网络ID是否正确 |
| 500+ | 服务器错误 | 使用指数退避策略重试 |
Best Practices
最佳实践
Security
安全
- Never commit API keys to git
- Use environment variables
- Rotate keys periodically
- Use separate keys for dev/prod
- 切勿将API密钥提交到Git仓库
- 使用环境变量存储密钥
- 定期轮换API密钥
- 开发和生产环境使用不同的密钥
Performance
性能
- Batch token requests when possible
- Cache frequently accessed data
- Use appropriate timeframes for OHLCV
- Implement request queuing for rate limits
- 尽可能批量查询代币数据
- 对频繁访问的数据进行缓存
- 为OHLCV选择合适的时间范围
- 实现请求队列处理调用频率限制
Data Quality
数据质量
- Verify market cap data (may be null if unverified)
- Check pool liquidity before trusting prices
- Use multiple timeframes for price analysis
- Monitor last trade timestamp for activity
- 验证市值数据(未经验证的代币可能返回null)
- 在信任价格前检查流动性池的资金储备
- 使用多时间范围进行价格分析
- 监控最新交易时间戳以确认活跃度
Resources
资源
Skill Structure
技能结构
coingecko/
├── SKILL.md # This file
├── resources/
│ ├── api-reference.md # Complete API endpoint reference
│ ├── network-dex-ids.md # Solana network and DEX identifiers
│ └── token-addresses.md # Common Solana token addresses
├── examples/
│ ├── token-prices/
│ │ └── get-token-price.ts # Token price examples
│ ├── pools/
│ │ └── pool-data.ts # Pool data examples
│ ├── ohlcv/
│ │ └── ohlcv-charts.ts # OHLCV chart examples
│ ├── trades/
│ │ └── recent-trades.ts # Trade history examples
│ └── integration/
│ └── full-client.ts # Complete client example
├── templates/
│ └── coingecko-client.ts # Production-ready client template
└── docs/
└── troubleshooting.md # Common issues and solutionscoingecko/
├── SKILL.md # 本文件
├── resources/
│ ├── api-reference.md # 完整API端点参考
│ ├── network-dex-ids.md # Solana网络及DEX标识符
│ └── token-addresses.md # 常见Solana代币地址
├── examples/
│ ├── token-prices/
│ │ └── get-token-price.ts # 代币价格示例
│ ├── pools/
│ │ └── pool-data.ts # 流动性池数据示例
│ ├── ohlcv/
│ │ └── ohlcv-charts.ts # OHLCV图表示例
│ ├── trades/
│ │ └── recent-trades.ts # 交易历史示例
│ └── integration/
│ └── full-client.ts # 完整客户端示例
├── templates/
│ └── coingecko-client.ts # 生产级客户端模板
└── docs/
└── troubleshooting.md # 常见问题及解决方案