cg-common
Shared infrastructure library for CoinGecko and crypto data CLI tools.
Features
- HTTP Client - Async client with automatic rate limiting and retry
- Rate Limiting - Governor-based rate limiter (10 req/min default for CoinGecko free tier)
- Retry Logic - Exponential backoff with special handling for 429 rate limits
- Symbol Resolution - Maps crypto symbols (BTC, ETH) to CoinGecko IDs (bitcoin, ethereum)
- Output Writers - JSON and CSV writers with pretty-print support
Usage
use ;
// Build HTTP client with rate limiting
let client = new
.with_rate_limit // 10 requests per minute
.build?;
// Resolve symbol to CoinGecko ID
let id = resolve_symbol; // Returns "bitcoin"
// Make API request (auto-retries on 429)
let response = client.get.await?;
// Write JSON output
let writer = new;
writer.write?;
Supported Symbols
50+ pre-mapped symbols including:
| Symbol | CoinGecko ID |
|---|---|
| BTC | bitcoin |
| ETH | ethereum |
| SOL | solana |
| XRP | ripple |
| DOGE | dogecoin |
| ADA | cardano |
| ... | ... |
Use resolve_symbol() to convert any symbol, or pass CoinGecko IDs directly.
Rate Limiting
The client implements conservative rate limiting for CoinGecko's free tier:
- Default: 10 requests/minute
- Automatic retry on 429 with 30s/60s/120s backoff
- Configurable via
with_rate_limit()
License
MIT