Using npm:
$ npm install exchain
Other Installations:
$ yarn add exchain
$ pnpm add exchain
import exchain from 'exchain';
(async () => {
// Get Rates
var getRates = await exchain.getRates({
amount: 2,
base: 'USD',
to: ['AUD', 'EUR', 'GBP', 'TRY'],
toFixed: 2
});
console.log(getRates);
/*
{
amount: 2,
base: 'USD',
date: '2024-10-22',
rates: { AUD: 2.99, EUR: 1.85, GBP: 1.54, TRY: 68.5 }
}
*/
// Get Rates with date
var getRatesWithDate = await exchain.getRates({
amount: 2,
base: 'USD',
to: ['AUD', 'EUR', 'GBP', 'TRY'],
startDate: '2024-10-15',
endDate: '2024-10-22',
});
console.log(getRatesWithDate);
/*
{
amount: 2,
base: 'USD',
start_date: '2024-10-15',
end_date: '2024-10-22',
rates: {
'2024-10-15': { AUD: 2.9783, EUR: 1.8344, GBP: 1.529, TRY: 68.516 },
'2024-10-16': { AUD: 2.99, EUR: 1.8354, GBP: 1.5345, TRY: 68.421 },
'2024-10-17': { AUD: 2.9869, EUR: 1.8406, GBP: 1.5361, TRY: 68.318 },
'2024-10-18': { AUD: 2.9805, EUR: 1.8438, GBP: 1.5334, TRY: 68.585 },
'2024-10-21': { AUD: 2.9909, EUR: 1.8428, GBP: 1.5353, TRY: 68.509 },
'2024-10-22': { AUD: 2.9899, EUR: 1.8483, GBP: 1.5403, TRY: 68.496 }
}
}
*/
// Get Currencies
var getCurrencies = await exchain.getCurrencies();
console.log(getCurrencies);
/*
{
AUD: 'Australian Dollar',
BGN: 'Bulgarian Lev',
BRL: 'Brazilian Real',
CAD: 'Canadian Dollar',
CHF: 'Swiss Franc',
CNY: 'Chinese Renminbi Yuan',
CZK: 'Czech Koruna',
DKK: 'Danish Krone',
EUR: 'Euro',
GBP: 'British Pound',
HKD: 'Hong Kong Dollar',
HUF: 'Hungarian Forint',
IDR: 'Indonesian Rupiah',
ILS: 'Israeli New Sheqel',
INR: 'Indian Rupee',
ISK: 'Icelandic Króna',
JPY: 'Japanese Yen',
KRW: 'South Korean Won',
MXN: 'Mexican Peso',
MYR: 'Malaysian Ringgit',
NOK: 'Norwegian Krone',
NZD: 'New Zealand Dollar',
PHP: 'Philippine Peso',
PLN: 'Polish Złoty',
RON: 'Romanian Leu',
SEK: 'Swedish Krona',
SGD: 'Singapore Dollar',
THB: 'Thai Baht',
TRY: 'Turkish Lira',
USD: 'United States Dollar',
ZAR: 'South African Rand'
}
*/
})();
exchain is licensed under the MIT License. See the LICENSE file for details.