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
npm install @tetherto/wdk-pricing-coingecko-httpInstall the shared provider package when you want caching or failover:
npm install @tetherto/wdk-pricing-coingecko-http @tetherto/wdk-pricing-providerCreate a 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
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
const client = new CoingeckoPricingClient({
apiKey: process.env.COINGECKO_API_KEY
})For CoinGecko Pro, set the Pro base URL too:
const client = new CoingeckoPricingClient({
baseURL: 'https://pro-api.coingecko.com/api/v3',
apiKey: process.env.COINGECKO_PRO_API_KEY
})