WDK logoWDK documentation

Get Started

Install @tetherto/wdk-pricing-coingecko-http and create a CoinGecko pricing client.

This guide covers installing the package, creating a CoingeckoPricingClient, and making a first current-price request.

Installation

Install with npm
npm install @tetherto/wdk-pricing-coingecko-http

Install the shared provider package when you want caching or failover:

Install with PricingProvider
npm install @tetherto/wdk-pricing-coingecko-http @tetherto/wdk-pricing-provider

Create a Client

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

const client = new CoingeckoPricingClient()

The no-options constructor uses CoinGecko's public API host.

Fetch a Price

Fetch BTC/USD
const btcUsd = await client.getCurrentPrice('BTC', 'USD')

if (btcUsd === null) {
  console.log('BTC/USD is unavailable from CoinGecko')
} else {
  console.log('BTC/USD:', btcUsd)
}

BTC is resolved to the CoinGecko ID bitcoin, and USD is sent as usd.

Add an API Key

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

For CoinGecko Pro, set the Pro base URL too:

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

Next Steps

On this page