WDK logoWDK documentation

Pricing CoinGecko HTTP Configuration

Configure @tetherto/wdk-pricing-coingecko-http options.

Configuration

Create a CoingeckoPricingClient with no options for public CoinGecko API access:

Public CoinGecko client
import { CoingeckoPricingClient } from '@tetherto/wdk-pricing-coingecko-http'

const client = new CoingeckoPricingClient()

The public host is https://api.coingecko.com/api/v3.

Options

OptionTypeDefaultDescription
baseURLstringhttps://api.coingecko.com/api/v3CoinGecko API base URL. Use https://pro-api.coingecko.com/api/v3 with a Pro key.
apiKeystringnoneCoinGecko API key. The client chooses x-cg-demo-api-key or x-cg-pro-api-key from baseURL.
coinIdsRecord<string, string>built-in mapSymbol-to-CoinGecko-ID overrides merged on top of defaults.

API Keys

Pass apiKey when you want CoinGecko authenticated requests:

Demo API key
const demoClient = new CoingeckoPricingClient({
  apiKey: process.env.COINGECKO_API_KEY
})

Use the Pro API host with a Pro key:

Pro API key
const proClient = new CoingeckoPricingClient({
  baseURL: 'https://pro-api.coingecko.com/api/v3',
  apiKey: process.env.COINGECKO_PRO_API_KEY
})

When baseURL includes pro-api.coingecko.com, the client sends the key with x-cg-pro-api-key. Otherwise it sends x-cg-demo-api-key.

Coin ID Overrides

CoinGecko uses asset IDs such as bitcoin, ethereum, and tether-gold. Tickers are not always enough to derive the correct ID, so the client keeps a small default map and lets you extend it.

Add custom symbols
const client = new CoingeckoPricingClient({
  coinIds: {
    PEPE: 'pepe',
    SHIB: 'shiba-inu'
  }
})

const pepeUsd = await client.getCurrentPrice('PEPE', 'USD')

You can also override a built-in mapping:

Override a default symbol
const client = new CoingeckoPricingClient({
  coinIds: {
    BTC: 'wrapped-bitcoin'
  }
})

Provider Failover

Use CoingeckoPricingClient as a fallback behind another pricing client by passing an ordered array to PricingProvider:

Fail over to CoinGecko
import { PricingProvider } from '@tetherto/wdk-pricing-provider'
import { BitfinexPricingClient } from '@tetherto/wdk-pricing-bitfinex-http'
import { CoingeckoPricingClient } from '@tetherto/wdk-pricing-coingecko-http'

const provider = new PricingProvider({
  client: [
    new BitfinexPricingClient(),
    new CoingeckoPricingClient({ apiKey: process.env.COINGECKO_API_KEY })
  ],
  retries: 1
})

const btcUsd = await provider.getLastPrice('BTC', 'USD')

The provider failover layer retries connection errors. A pair that resolves to null is still an unavailable result for that client.

Runtime Notes

  • Install @tetherto/wdk-pricing-provider when you want caching or failover through PricingProvider.
  • The package exposes a Bare runtime entrypoint through its package export map.
  • Integration tests hit the live CoinGecko API and can fail with 429 under repeated free-tier runs.

On this page