Rates API
Get exchange rates between currencies.
Get Rates
const response = await afriex.rates.getRates({
base: 'USD,NGN',
symbols: 'NGN,USD,GBP,KES'
});
console.log(response.rates);
// {
// USD: { NGN: '1550.00', GBP: '0.79', KES: '129.50' },
// NGN: { USD: '0.00065', GBP: '0.00051', KES: '0.0835' }
// }
console.log(response.updatedAt); // TimestampParameters:
| Field | Type | Description |
|---|---|---|
base | string | string[] | Base currencies (comma-separated or array) |
symbols | string | string[] | Target currencies to get rates for |
Get Single Rate
Get the exchange rate between two specific currencies:
const rate = await afriex.rates.getRate('USD', 'NGN');
console.log('USD to NGN:', rate); // "1550.00"Convert Amount
Convert an amount from one currency to another:
const result = await afriex.rates.convert(100, 'USD', 'NGN');
console.log('100 USD in NGN:', result); // 155000Response Format
{
rates: {
[baseCurrency: string]: {
[targetCurrency: string]: string
}
},
base: string[],
updatedAt: number // Unix timestamp
}Last updated on