API Reference
Rates API
Get exchange rates between currencies.
Get Rates
const response = await afriex.rates.getRates({
fromSymbols: "USD,NGN",
toSymbols: "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); // Unix timestampBoth filters are optional. With neither, you get the rates from USD to every currency:
const usdRates = await afriex.rates.getRates();Parameters:
| Field | Type | Default | Description |
|---|---|---|---|
fromSymbols | string | string[] | USD only | Base currencies (comma-separated or array) |
toSymbols | string | string[] | Every target currency | Target currencies |
To get the rates from other currencies, name them in fromSymbols.
Get Single Rate
const rate = await afriex.rates.getRate("USD", "NGN");
console.log("USD to NGN:", rate); // "1550.00"Throws if either symbol is unsupported, or if the pair has no published rate —
it never returns a "0" rate that would silently zero out a conversion.
Convert Amount
const result = await afriex.rates.convert(100, "USD", "NGN");
console.log("100 USD in NGN:", result); // 155000Response Format
{
rates: {
[fromSymbol: string]: {
[toSymbol: string]: string
}
},
updatedAt: number // Unix timestamp
}