DEV Community

allratestoday
allratestoday

Posted on

HMRC, IRS, US Treasury, Swiss Customs: Tax Authority Exchange Rates as JSON

Central banks are not the only institutions that set exchange rates. Several tax and customs authorities issue their own tables, and their rules require those tables instead:

Authority Code Table Typical use
UK HM Revenue & Customs hmrc Monthly UK customs and VAT on imports
US Internal Revenue Service irs Yearly averages US tax reporting of foreign income
US Department of the Treasury ustreasury Quarterly Federal agency reporting
Swiss Federal Office for Customs and Border Security bazg Daily Swiss customs and VAT
SUNAT (Peru) sunat Daily Peruvian tax and customs
India CBIC cbic Notified periodically Indian customs valuation

These figures often differ from the central bank's rate for the same currency, and from the market. If a filing names HMRC, the HMRC table is the only correct answer.

Same endpoint as the central banks

AllRatesToday serves tax authority rates through the same endpoints as its 123 central banks, so one function covers all of them:

const KEY = process.env.ALLRATES_KEY;

async function officialRate(sourceCode, from, to) {
  const url = `https://allratestoday.com/api/v1/central-bank/${sourceCode}/latest?source=${from}&target=${to}`;
  const r = await fetch(url, { headers: { Authorization: `Bearer ${KEY}` } });
  return r.json();
}

console.log(await officialRate('hmrc', 'USD', 'GBP'));
console.log(await officialRate('bazg', 'EUR', 'CHF'));
console.log(await officialRate('ustreasury', 'USD', 'MXN'));
Enter fullscreen mode Exit fullscreen mode

Each response carries rate_date, the date the authority's table applies to. For HMRC that is a month, and for the US Treasury a quarter. Store it with the transaction.

Quarterly tables don't go stale

A quarterly or monthly table remains legally in force for its whole period. The API keeps returning it, and when you ask for every source side by side (/api/v1/central-banks/rates), it marks old tables as such instead of dropping them.

Where the other two layers fit

A customs broker or cross-border seller usually needs more than the tax table:

  • Live mid-market (/api/v1/rates) to quote prices to customers.
  • The tax authority rate to value the declaration.
  • A commercial bank's board (/api/v1/bank-rates/...) to know what the payment will actually convert at.

AllRatesToday serves all three from one key; we haven't found another API that does.

Docs: allratestoday.com/docs ยท Free key: allratestoday.com/register

Top comments (0)