Skip to content

BitPay Exchange Rates API wrapper for Node.js - A tiny and easy to use library

Notifications You must be signed in to change notification settings

colkito/bitpay-rates

Repository files navigation

bitpay-rates

GitHub Workflow Status BundlePhobia BundlePhobia

A lightweight Node.js wrapper for BitPay's exchange rates API, now in TypeScript.

Zero-dependency and promise support for easy integration into your project. ✨

Requirements

  • nodejs >= 12.x

Examples

Getting a rate by code:

import bitpayRates from 'bitpay-rates';

const code = 'ARS'; // see list of codes below

// Using async/await
try {
  const rate = await bitpayRates.get(code);
  console.log(`[Async/Await][${code}] Rate:`, rate);
} catch (err) {
  console.error(`[Async/Await][${code}] Error:`, err);
}

Handling an invalid currency code:

import bitpayRates from 'bitpay-rates';

// Handling an invalid currency code
bitpayRates
  .get('INVALID')
  .then((rate) => console.log('[Promise][INVALID] Rate:', rate))
  .catch((err) => console.error('[Promise][INVALID] Error:', err));

Successful response:

{
  "code": "ARS",
  "name": "Argentine Peso",
  "rate": 60612542.16
}

Getting all the rates:

import bitpayRates from 'bitpay-rates';

// Using async/await
try {
  const rates = await bitpayRates.get();
  console.log('[Async/Await] Rates:', rates);
} catch (err) {
  console.error('[Async/Await] Error:', err);
}

// Handling an invalid currency code
bitpayRates
  .get('INVALID')
  .then((rate) => console.log('[Promise][INVALID] Rate:', rate))
  .catch((err) => console.error('[Promise][INVALID] Error:', err));

Successful response:

[
  {
    "code": "ARS",
    "name": "Argentine Peso",
    "rate": 5291987.02
  },
  {
    "code": "BUSD",
    "name": "Binance USD",
    "rate": 57818.28
  },
  {...}
]

More examples here.

Available Codes (updated: 2024-01-24)

Follow this link to see the complete list of codes.

Related Packages