Latest Rates
Get the latest exchange rate between any two supported currencies.
GET
https://afrotools.com/api/forex
Authentication required. Pass your API key via
x-api-key header. Learn more
Request Parameters
| Parameter | Type | Description |
|---|---|---|
| from required | string | Source currency code (e.g., USD, EUR, GBP, BTC). |
| to required | string | Target currency code (e.g., NGN, KES, ZAR). |
| amount optional | number | Amount to convert. Default: 1. |
| date optional | string | Historical date in YYYY-MM-DD format. Omit for latest. Pro plan required. |
Response Fields
| Field | Type | Description |
|---|---|---|
| from | string | Source currency code. |
| to | string | Target currency code. |
| rate | number | Mid-market exchange rate. |
| bid | number | Bid price (buy rate). |
| ask | number | Ask price (sell rate). |
| amount | number | Converted amount (if amount param was provided). |
| change_24h | number | Absolute change in last 24 hours. |
| change_pct_24h | number | Percentage change in last 24 hours. |
| timestamp | string | ISO 8601 timestamp of the rate. |
| source | string | Data source (e.g., CBN, SARB, CBK). |
Error Responses
| Status | Code | Description |
|---|---|---|
| 400 | invalid_currency | One or both currency codes are not supported. |
| 400 | invalid_date | Date format is invalid or date is in the future. |
| 401 | missing_api_key | No API key was provided. |
| 403 | plan_required | Historical data requires Pro plan or above. |
| 429 | rate_limit_exceeded | Rate limit exceeded. |
Request Examples
curl "https://afrotools.com/api/forex?from=USD&to=NGN" \
-H "x-api-key: afro_live_your_key_here"
const res = await fetch(
"https://afrotools.com/api/forex?from=USD&to=NGN",
{ headers: { "x-api-key": "afro_live_your_key_here" } }
);
const data = await res.json();
console.log(`1 USD = ${data.data.rate} NGN`);
import requests
resp = requests.get(
"https://afrotools.com/api/forex",
params={"from": "USD", "to": "NGN"},
headers={"x-api-key": "afro_live_your_key_here"}
)
data = resp.json()
print(f"1 USD = {data['data']['rate']} NGN")
const axios = require("axios");
const { data } = await axios.get(
"https://afrotools.com/api/forex",
{
params: { from: "USD", to: "NGN" },
headers: { "x-api-key": "afro_live_your_key_here" }
}
);
console.log(`1 USD = ${data.data.rate} NGN`);
$ch = curl_init(
"https://afrotools.com/api/forex?from=USD&to=NGN"
);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
"x-api-key: afro_live_your_key_here"
]);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
$data = json_decode($response, true);
echo "1 USD = " . $data["data"]["rate"] . " NGN";
Response (200 OK)
{
"success": true,
"data": {
"from": "USD",
"to": "NGN",
"rate": 1580.25,
"bid": 1578.50,
"ask": 1582.00,
"change_24h": -0.35,
"change_pct_24h": -0.022,
"timestamp": "2026-03-15T10:30:00Z",
"source": "CBN"
}
}
With Amount Conversion
# Convert 1000 USD to NGN
curl "https://afrotools.com/api/forex?from=USD&to=NGN&amount=1000" \
-H "x-api-key: afro_test_abc123"
{
"success": true,
"data": {
"from": "USD",
"to": "NGN",
"rate": 1580.25,
"amount": 1580250.00,
"bid": 1578500.00,
"ask": 1582000.00,
"timestamp": "2026-03-15T10:30:00Z",
"source": "CBN"
}
}