cg-common 0.2.1

Shared library for CoinGecko CLI tools - HTTP client with rate limiting, retry logic, symbol resolution, and output writers
Documentation

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 cg_common::{CoinGeckoClientBuilder, resolve_symbol, JsonWriter};

// Build HTTP client with rate limiting
let client = CoinGeckoClientBuilder::new()
    .with_rate_limit(10)  // 10 requests per minute
    .build()?;

// Resolve symbol to CoinGecko ID
let id = resolve_symbol("BTC");  // Returns "bitcoin"

// Make API request (auto-retries on 429)
let response = client.get("/coins/bitcoin").await?;

// Write JSON output
let writer = JsonWriter::new(Some("output.json".into()), true);
writer.write(&data)?;

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