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. ✨
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.
Follow this link to see the complete list of codes.