A tiny Node.js wrapper for the BitPay Rates API
npm install bitpay-rates!GitHub Workflow Status


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. ✨
- nodejs >= 12.x
Getting a rate by code:
``js
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);[Async/Await][${code}] Error:
} catch (err) {
console.error(, err);`
}
Handling an invalid currency code:
`js
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:
`json`
{
"code": "ARS",
"name": "Argentine Peso",
"rate": 60612542.16
}
Getting all the rates:
`js
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:
`json``
[
{
"code": "ARS",
"name": "Argentine Peso",
"rate": 5291987.02
},
{
"code": "BUSD",
"name": "Binance USD",
"rate": 57818.28
},
{...}
]
More examples here.
Follow this link to see the complete list of codes.