@coinpaprika/api-nodejs-client
v3.0.0
Published
This library provides convenient way to use Coinpaprika.com API in NodeJS
Downloads
316
Readme
Coinpaprika API NodeJS Client
This library provides convenient way to use Coinpaprika.com API in NodeJS.
Coinpaprika delivers full market data to the world of crypto: coin prices, volumes, market caps, ATHs, return rates and more.
Install
npm install @coinpaprika/api-nodejs-clientRequires Node.js 18 or newer (uses the built-in global fetch). If you need to support Node 14–17, stay on the 2.x line.
Usage
CommonJS
const CoinpaprikaAPI = require('@coinpaprika/api-nodejs-client');
const client = new CoinpaprikaAPI();
client.getGlobal().then(console.log).catch(console.error);
client.getCoin('btc-bitcoin').then(console.log).catch(console.error);ESM
import CoinpaprikaAPI from '@coinpaprika/api-nodejs-client';
const client = new CoinpaprikaAPI();
const data = await client.getGlobal();TypeScript
Type declarations ship with the package — no @types install needed.
import CoinpaprikaAPI from '@coinpaprika/api-nodejs-client';
const client = new CoinpaprikaAPI({ apiKey: process.env.COINPAPRIKA_KEY });
const markets = await client.getCoinMarkets('btc-bitcoin', { quotes: ['USD', 'BTC'] });Check out the Coinpaprika API documentation for more information!
Configuration
const client = new CoinpaprikaAPI({
version: 'v1', // API version (default 'v1')
pro: true, // Use Pro host (api-pro.coinpaprika.com). Default false.
baseUrl: 'https://api.coinpaprika.com',// Override entirely (wins over `pro`)
apiKey: process.env.COINPAPRIKA_KEY, // Sent as `Authorization: <key>` per Coinpaprika docs (no Bearer prefix)
retry: { attempts: 3, delay: 300 }, // Opt-in retry on 408/425/429/5xx & network errors (exponential backoff)
config: { // Passed straight to fetch(url, config)
headers: { 'User-Agent': 'my-app/1.0' },
signal: controller.signal // AbortSignal for cancellation (see below)
},
fetcher: customFetch // Optional: override the fetch implementation
});Pro API key
Pro-tier endpoints (getCoinsMappings, getChangelogIds, getKeyInfo, and some fields on public endpoints) require an API key and the Pro host (https://api-pro.coinpaprika.com). The client sends the key exactly as documented — Authorization: <key> (no Bearer prefix).
const client = new CoinpaprikaAPI({
pro: true,
apiKey: process.env.COINPAPRIKA_KEY
});
await client.getKeyInfo();Request cancellation
Client-wide (all calls on this client share the signal):
const controller = new AbortController();
const client = new CoinpaprikaAPI({ config: { signal: controller.signal } });
const p = client.getCoins();
setTimeout(() => controller.abort(), 100);
try { await p } catch (e) { /* AbortError */ }Per-call via withSignal(signal) — returns a new client bound to that signal; the original is untouched:
const client = new CoinpaprikaAPI();
const controller = new AbortController();
const p = client.withSignal(controller.signal).getCoins();
setTimeout(() => controller.abort(), 100);
try { await p } catch (e) { /* AbortError on the scoped call only */ }
// The parent client keeps working:
await client.getGlobal();Retries
Opt in via retry. Retries only on transient failures (408, 425, 429, 500–504, network errors); 2xx/4xx (besides the above) are returned as-is. Exponential backoff: delay * 2^(attempt-1).
API Coverage
const CoinpaprikaAPI = require('@coinpaprika/api-nodejs-client')
const client = new CoinpaprikaAPI()Market Data
client.getGlobal() // Global market overview
client.getCoins() // List all coins
client.getCoin('btc-bitcoin') // Coin details
client.getCoin('btc-bitcoin', { quotes: ['USD', 'BTC'] }) // Coin details with quotes
getTickerandgetAllTickerswere removed in 3.0.0 (upstream/tickerendpoint is deprecated). UsegetCoin,getCoinsOHLCVLatest, andgetCoinsOHLCVHistoricalinstead. See the CHANGELOG for migration snippets.
OHLCV
client.getCoinsOHLCVLatest('btc-bitcoin') // Latest full day OHLCV
client.getCoinsOHLCVToday('btc-bitcoin') // Today's OHLCV (live)
client.getCoinsOHLCVHistorical({ coinId: 'btc-bitcoin', start: '2024-01-01' }) // HistoricalCoins
client.getCoinTwitter('btc-bitcoin') // Twitter timeline
client.getCoinEvents('btc-bitcoin') // Coin events
client.getCoinExchanges('btc-bitcoin') // Exchanges listing coin
client.getCoinMarkets('btc-bitcoin', { quotes: ['USD', 'BTC'] }) // Markets for coin (array or CSV string)
client.getCoinsMappings() // ID mappings (Pro)Exchanges
client.getExchanges() // List all exchanges
client.getExchange('binance') // Exchange details
client.getExchangeMarkets('binance', { quotes: ['USD', 'BTC'] }) // Markets on exchange (array or CSV string)Contracts
client.getPlatforms() // List contract platforms
client.getContracts('eth-ethereum') // Contracts on Ethereum
client.getTickerByContract('eth-ethereum', '0xdac1...') // Ticker by contract
client.getHistoricalByContract('eth-ethereum', '0xdac1...', { start: '2024-01-01' })Other
client.search({ q: 'bitcoin', c: 'currencies', limit: 10 })
client.priceConverter({ base_currency_id: 'btc-bitcoin', quote_currency_id: 'usd-us-dollars', amount: 1 })
client.getPeople('satoshi-kobayashi') // Person details
client.getTags() // List tags
client.getTag('blockchain-service') // Tag details
client.getKeyInfo() // API key info (requires key)
client.getChangelogIds() // Recent changelog IDs (Pro)Notes on query params
- Any param that accepts multiple values (e.g.
quotes,cforsearch) can be passed as either a CSV string or an array; arrays are joined with commas automatically before being sent to the API. - Required params are validated synchronously and throw a descriptive
Errorbefore any network call (e.g.client.search({})throws"q (search query) is required").
Changelog
See CHANGELOG.md for release notes.
License
CoinpaprikaAPI is available under the MIT license. See the LICENSE file for more info.
