Lightweight Node.js library and CLI for real-time mid-market currency exchange rates β 160+ currencies sourced from Refinitiv (Reuters) and interbank feeds via the AllRatesToday API.
- β‘ Real-time rates, not daily snapshots
- π 160+ currencies including majors, emerging-market, precious metals (XAU, XAG)
- π¦ Zero runtime dependencies (uses native
fetch) - π₯οΈ Works as a Node library AND CLI
- π Mid-market rates (no retail markup)
npm install fx-ratesOr with yarn / pnpm:
yarn add fx-rates
pnpm add fx-ratesThis package calls the authenticated AllRatesToday API. Grab a free key at allratestoday.com/register β no credit card required.
Export it once:
export ALLRATESTODAY_API_KEY="art_live_..."Or pass it explicitly to each call (see below).
import { rate } from "fx-rates";
const r = await rate("USD", "INR");
console.log(r);
// {
// date: "2026-04-20",
// base: "USD",
// target: "INR",
// rate: 83.2145
// }import { convert } from "fx-rates";
const out = await convert(100, "USD", "EUR");
console.log(out);
// {
// from: { currency: "USD", amount: 100 },
// to: { currency: "EUR", amount: 92.34 },
// rate: 0.9234,
// date: "2026-04-20"
// }const r = await rate("GBP", "USD", { apiKey: "art_live_..." });import { rate, RateResult, RateOptions } from "fx-rates";
const opts: RateOptions = { timeoutMs: 5000 };
const r: RateResult = await rate("EUR", "JPY", opts);import { rate } from "fx-rates";
import fetch from "node-fetch";
const r = await rate("USD", "INR", { fetch });Install globally:
npm install -g fx-ratesThen:
$ fx-rates USD INR
{
"date": "2026-04-20",
"base": "USD",
"target": "INR",
"rate": 83.2145
}Convert an amount (third positional argument):
$ fx-rates USD EUR 250
{
"from": { "currency": "USD", "amount": 250 },
"to": { "currency": "EUR", "amount": 230.85 },
"rate": 0.9234,
"date": "2026-04-20"
}Pipe into jq:
$ fx-rates GBP USD | jq '.rate'
1.3512Fetch the latest mid-market rate for a single pair.
| Param | Type | Description |
|---|---|---|
base |
string | ISO 4217 code of the source currency ("USD", "EUR", "XAU", β¦) |
target |
string | ISO 4217 code of the target currency |
options |
object | Optional (see below) |
Returns Promise<RateResult>:
interface RateResult {
date: string; // ISO date, e.g. "2026-04-20"
base: string; // "USD"
target: string; // "INR"
rate: number; // 83.2145
}Multiply an amount by the current rate.
interface RateOptions {
apiKey?: string; // defaults to process.env.ALLRATESTODAY_API_KEY
baseUrl?: string; // override for staging / self-hosted proxies
fetch?: typeof fetch; // custom fetch implementation
timeoutMs?: number; // default 15000
}All errors are thrown as AllRatesTodayError with a .status field (HTTP status where applicable):
import { rate, AllRatesTodayError } from "fx-rates";
try {
await rate("USD", "XXX");
} catch (err) {
if (err instanceof AllRatesTodayError) {
console.error(err.status, err.message);
}
}160+ currencies including majors (USD, EUR, GBP, JPY, CHF, CAD, AUD, NZD), emerging-market currencies (INR, CNY, BRL, MXN, TRY, ZAR, SGD, HKD, KRW, THB, PHP, PKR, BDT, LKR, NGN, GHS, KES, AED, SAR, EGP), and precious metals (XAU, XAG).
Full list: allratestoday.com/api/v1/symbols.
moneyifyβ Cashify-compatible converter with the same auto-fetch backing. Use when you need conversion math, expression parsing ("10 USD to EUR"), or big.js precision.@allratestoday/sdkβ Full-featured SDK with historical data, batch requests, and webhooks.react-currency-localizer-realtimeβ React hooks and components for auto-localized pricing.allratestodayβ The REST API that powers this package.
This project contains code generated by Large Language Models (LLMs), under human supervision and proofreading. All published versions are reviewed, tested, and released by a human maintainer.
MIT Β© AllRatesToday β maintained by Chathuranga Basnayaka.