@allratestoday/hmrc-exchange-rate 1.1.2 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +207 -25
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,65 +1,247 @@
|
|
|
1
|
-
# HM Revenue & Customs Exchange Rate API
|
|
1
|
+
# HM Revenue & Customs Exchange Rate API — hmrc-exchange-rate
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[](https://www.npmjs.com/package/@allratestoday/hmrc-exchange-rate)
|
|
4
|
+
[](https://github.com/AllRates-Today/hmrc-exchange-rate/blob/main/LICENSE)
|
|
5
|
+
[](https://www.npmjs.com/package/@allratestoday/hmrc-exchange-rate)
|
|
6
|
+
[](https://www.typescriptlang.org/)
|
|
4
7
|
|
|
5
|
-
|
|
8
|
+
**Official HM Revenue & Customs (the United Kingdom) monthly exchange rates for Node.js and TypeScript. The published tax authority rates behind tax filings, customs valuations, audits, and compliant invoicing — not market estimates, but the numbers HM Revenue & Customs itself prints, every month.**
|
|
6
9
|
|
|
7
|
-
|
|
10
|
+
## 🚀 Why this client?
|
|
8
11
|
|
|
9
|
-
|
|
12
|
+
- 🏛️ **Official published rates** — HM Revenue & Customs's own table, with the publisher's own `rate_date` on every response
|
|
13
|
+
- 📅 **History back to 2021** — point-in-time tables and daily series for any past date
|
|
14
|
+
- 🔀 **Published vs derived, always flagged** — computed inverse/cross pairs carry `derived: true`, never mixed with official prints
|
|
15
|
+
- ⚡ **Zero dependencies** — pure ESM + CJS over global `fetch`; Node 18+, Bun, Deno, and edge runtimes
|
|
16
|
+
- 🔷 **Type-safe** — full TypeScript definitions shipped with the package
|
|
17
|
+
- 🧾 **Compliance-grade metadata** — `rate_type`, publication date, and source disclaimer on every response
|
|
18
|
+
|
|
19
|
+
## 🔑 Get your API key
|
|
20
|
+
|
|
21
|
+
Get a free API key at [allratestoday.com/register](https://allratestoday.com/register) — no credit card required. Latest rates are on every plan, including free.
|
|
22
|
+
|
|
23
|
+
## 📦 Installation
|
|
10
24
|
|
|
11
25
|
```bash
|
|
12
26
|
npm install @allratestoday/hmrc-exchange-rate
|
|
13
27
|
```
|
|
14
28
|
|
|
15
|
-
|
|
29
|
+
```bash
|
|
30
|
+
yarn add @allratestoday/hmrc-exchange-rate
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
pnpm add @allratestoday/hmrc-exchange-rate
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
Scoped mirror of [`hmrc-exchange-rate`](https://www.npmjs.com/package/hmrc-exchange-rate) — same code, same versions.
|
|
38
|
+
|
|
39
|
+
## 🏁 Quick start
|
|
16
40
|
|
|
17
41
|
```js
|
|
18
|
-
import { getRate
|
|
42
|
+
import { getRate } from '@allratestoday/hmrc-exchange-rate';
|
|
19
43
|
|
|
20
|
-
// One pair at the official HM Revenue & Customs rate
|
|
21
44
|
const pair = await getRate('GBP', 'USD', { apiKey: 'art_live_...' });
|
|
22
|
-
console.log(pair.rate, pair.rate_date); //
|
|
45
|
+
console.log(pair.rate, pair.rate_date); // the official HM Revenue & Customs rate, on the tax authority's own date
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
## 📚 API reference
|
|
49
|
+
|
|
50
|
+
- [Latest pair rate](#latest-pair-rate) — one pair from the latest published table
|
|
51
|
+
- [Full published table](#full-published-table) — everything the tax authority printed, in one call
|
|
52
|
+
- [Table for a date](#table-for-a-date) — the official table for an invoice or filing date
|
|
53
|
+
- [Daily time series](#daily-time-series) — one pair across a date range
|
|
54
|
+
|
|
55
|
+
---
|
|
56
|
+
|
|
57
|
+
### Latest pair rate
|
|
58
|
+
|
|
59
|
+
Free plan and up. Pairs the tax authority does not print directly are resolved from its table and flagged (see *Published vs derived rates* below).
|
|
60
|
+
|
|
61
|
+
```js
|
|
62
|
+
const pair = await getRate('GBP', 'USD', { apiKey: 'art_live_...' });
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
**Response:**
|
|
66
|
+
|
|
67
|
+
```javascript
|
|
68
|
+
{
|
|
69
|
+
bank: 'hmrc',
|
|
70
|
+
name: 'HM Revenue & Customs',
|
|
71
|
+
rate_date: '2026-08-01', // HM Revenue & Customs's own publication date
|
|
72
|
+
source: 'GBP',
|
|
73
|
+
target: 'USD',
|
|
74
|
+
rate: 1.3367,
|
|
75
|
+
rate_type: 'monthly',
|
|
76
|
+
derived: false,
|
|
77
|
+
method: 'published',
|
|
78
|
+
disclaimer: '…'
|
|
79
|
+
}
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
### Full published table
|
|
83
|
+
|
|
84
|
+
Free plan and up. The complete table for the latest publication date.
|
|
85
|
+
|
|
86
|
+
```js
|
|
87
|
+
import { getLatestRates } from '@allratestoday/hmrc-exchange-rate';
|
|
23
88
|
|
|
24
|
-
// The bank's full published table
|
|
25
89
|
const table = await getLatestRates({ apiKey: 'art_live_...' });
|
|
26
90
|
console.log(table.rate_date, table.rates.length);
|
|
27
91
|
```
|
|
28
92
|
|
|
29
|
-
|
|
93
|
+
**Response:**
|
|
94
|
+
|
|
95
|
+
```javascript
|
|
96
|
+
{
|
|
97
|
+
bank: 'hmrc',
|
|
98
|
+
name: 'HM Revenue & Customs',
|
|
99
|
+
rate_date: '2026-08-01',
|
|
100
|
+
rates: [
|
|
101
|
+
{ "base": "GBP", "quote": "USD", "type": "monthly", "value": 1.3367 },
|
|
102
|
+
// … the rest of the published table (141 currencies vs GBP)
|
|
103
|
+
],
|
|
104
|
+
disclaimer: '…'
|
|
105
|
+
}
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
### Table for a date
|
|
109
|
+
|
|
110
|
+
Paid plans. The official table for any date since 2021 — weekends and holidays return the most recent published date, flagged via `published_on_requested_date`, which is exactly the in-force rate a filing needs.
|
|
30
111
|
|
|
31
112
|
```js
|
|
32
|
-
import { getRatesForDate
|
|
113
|
+
import { getRatesForDate } from '@allratestoday/hmrc-exchange-rate';
|
|
33
114
|
|
|
34
|
-
// The official table for an invoice date — weekends/holidays return the
|
|
35
|
-
// most recent published date, flagged via published_on_requested_date.
|
|
36
115
|
const day = await getRatesForDate('2026-06-30', { apiKey: 'art_live_...' });
|
|
116
|
+
// Optionally narrow to one pair:
|
|
117
|
+
const one = await getRatesForDate('2026-06-30', { apiKey: 'art_live_...', source: 'GBP', target: 'USD' });
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
**Response:**
|
|
121
|
+
|
|
122
|
+
```javascript
|
|
123
|
+
{
|
|
124
|
+
bank: 'hmrc',
|
|
125
|
+
requested_date: '2026-06-30',
|
|
126
|
+
rate_date: '2026-06-30', // the date actually published
|
|
127
|
+
published_on_requested_date: true, // false when a weekend/holiday fell back
|
|
128
|
+
rates: [ /* the full table for that date */ ],
|
|
129
|
+
disclaimer: '…'
|
|
130
|
+
}
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
### Daily time series
|
|
134
|
+
|
|
135
|
+
Paid plans. One resolved rate per publication date — ready for charting, revaluation runs, or audit workpapers.
|
|
136
|
+
|
|
137
|
+
```js
|
|
138
|
+
import { getHistory } from '@allratestoday/hmrc-exchange-rate';
|
|
37
139
|
|
|
38
|
-
// Daily series for one pair
|
|
39
140
|
const series = await getHistory(
|
|
40
|
-
{ source: 'GBP', target: 'USD', from: '2026-01-01' },
|
|
141
|
+
{ source: 'GBP', target: 'USD', from: '2026-01-01', to: '2026-08-01' },
|
|
41
142
|
{ apiKey: 'art_live_...' }
|
|
42
143
|
);
|
|
43
144
|
```
|
|
44
145
|
|
|
45
|
-
|
|
146
|
+
**Response:**
|
|
147
|
+
|
|
148
|
+
```javascript
|
|
149
|
+
{
|
|
150
|
+
bank: 'hmrc',
|
|
151
|
+
source: 'GBP',
|
|
152
|
+
target: 'USD',
|
|
153
|
+
from: '2026-01-01',
|
|
154
|
+
to: '2026-08-01',
|
|
155
|
+
count: 152,
|
|
156
|
+
rates: [
|
|
157
|
+
// one entry per publication date
|
|
158
|
+
{ date: '2026-08-01', rate: 1.3367, rate_type: 'monthly', derived: false, method: 'published' },
|
|
159
|
+
// …
|
|
160
|
+
],
|
|
161
|
+
disclaimer: '…'
|
|
162
|
+
}
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
Pass `{ symbol: 'USD' }` instead of `source`/`target` to get the raw published rows for one currency (all rate types, no pair resolution).
|
|
166
|
+
|
|
167
|
+
---
|
|
168
|
+
|
|
169
|
+
## 🗺️ Currencies covered
|
|
46
170
|
|
|
47
171
|
HM Revenue & Customs currently publishes rates covering **142 currencies** (as of the latest table):
|
|
48
172
|
|
|
49
173
|
`AED` · `ALL` · `AMD` · `AOA` · `ARS` · `AUD` · `AWG` · `AZN` · `BAM` · `BBD` · `BDT` · `BHD` · `BIF` · `BMD` · `BND` · `BOB` · `BRL` · `BSD` · `BTN` · `BWP` · `BYN` · `BZD` · `CAD` · `CDF` · `CHF` · `CLP` · `CNY` · `COP` · `CRC` · `CUP` · `CVE` · `CZK` · `DJF` · `DKK` · `DOP` · `DZD` · `EGP` · `ERN` · `ETB` · `EUR` · `FJD` · `GBP` · `GEL` · `GHS` · `GMD` · `GNF` · `GTQ` · `GYD` · `HKD` · `HNL` · `HTG` · `HUF` · `IDR` · `ILS` · `INR` · `IQD` · `ISK` · `JMD` · `JOD` · `JPY` · `KES` · `KGS` · `KHR` · `KMF` · `KRW` · `KWD` · `KYD` · `KZT` · `LAK` · `LBP` · `LKR` · `LRD` · `LSL` · `LYD` · `MAD` · `MDL` · `MGA` · `MKD` · `MMK` · `MNT` · `MOP` · `MRU` · `MUR` · `MVR` · `MWK` · `MXN` · `MYR` · `MZN` · `NGN` · `NIO` · `NOK` · `NPR` · `NZD` · `OMR` · `PAB` · `PEN` · `PGK` · `PHP` · `PKR` · `PLN` · `PYG` · `QAR` · `RON` · `RSD` · `RUB` · `RWF` · `SAR` · `SBD` · `SCR` · `SDG` · `SEK` · `SGD` · `SLE` · `SOS` · `SRD` · `SVC` · `SZL` · `THB` · `TMT` · `TND` · `TOP` · `TRY` · `TTD` · `TWD` · `TZS` · `UAH` · `UGX` · `USD` · `UYU` · `UZS` · `VES` · `VND` · `VUV` · `WST` · `XAF` · `XCD` · `XOF` · `XPF` · `YER` · `ZAR` · `ZMW` · `ZWG`
|
|
50
174
|
|
|
51
|
-
|
|
175
|
+
## ⚖️ Published vs derived rates
|
|
176
|
+
|
|
177
|
+
If HM Revenue & Customs does not print a pair directly, the API resolves it from the tax authority's own table and says so — official and computed values are never confused:
|
|
178
|
+
|
|
179
|
+
| `method` | `derived` | Meaning |
|
|
180
|
+
| --- | --- | --- |
|
|
181
|
+
| `published` | `false` | The tax authority printed this pair directly |
|
|
182
|
+
| `inverse` | `true` | Computed as 1 ÷ the published opposite direction |
|
|
183
|
+
| `cross` | `true` | Computed via GBP from two published rates |
|
|
184
|
+
|
|
185
|
+
## 🛡️ Error handling
|
|
186
|
+
|
|
187
|
+
Errors are thrown as `Error` with `status` (HTTP code) and `body` (the API's JSON error) attached:
|
|
188
|
+
|
|
189
|
+
```js
|
|
190
|
+
try {
|
|
191
|
+
const pair = await getRate('GBP', 'XXX', { apiKey: 'art_live_...' });
|
|
192
|
+
} catch (err) {
|
|
193
|
+
console.log(err.message); // human-readable reason
|
|
194
|
+
console.log(err.status); // e.g. 404
|
|
195
|
+
}
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
| Status | Meaning |
|
|
199
|
+
| ------ | ------- |
|
|
200
|
+
| — | Missing `apiKey` (thrown before any request) |
|
|
201
|
+
| `400` | Malformed date or parameters |
|
|
202
|
+
| `401` | Invalid API key |
|
|
203
|
+
| `403` | Endpoint needs a [paid plan](https://allratestoday.com/pricing/) (historical dates & series) |
|
|
204
|
+
| `404` | Pair or date range not covered by HM Revenue & Customs |
|
|
205
|
+
| `429` | Monthly quota exceeded |
|
|
206
|
+
|
|
207
|
+
## 🔷 TypeScript
|
|
208
|
+
|
|
209
|
+
Full definitions ship with the package — no `@types` install:
|
|
210
|
+
|
|
211
|
+
```ts
|
|
212
|
+
import type { LatestRates, PairRate, DatedRates, RateEntry, HistoryQuery, RequestOptions } from '@allratestoday/hmrc-exchange-rate';
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
## 📦 CommonJS
|
|
216
|
+
|
|
217
|
+
```javascript
|
|
218
|
+
const { getRate } = require('@allratestoday/hmrc-exchange-rate');
|
|
219
|
+
|
|
220
|
+
getRate('GBP', 'USD', { apiKey: 'art_live_...' }).then((pair) => console.log(pair.rate));
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
## 💡 Quota tips
|
|
224
|
+
|
|
225
|
+
- Rates change once a month — cache the published table locally and a small monthly quota goes a long way.
|
|
226
|
+
- Every request counts toward your AllRatesToday quota, shared across all AllRatesToday endpoints on your key.
|
|
52
227
|
|
|
53
|
-
##
|
|
228
|
+
## 📖 Methods reference
|
|
54
229
|
|
|
55
|
-
|
|
230
|
+
| Method | Plan | Description |
|
|
231
|
+
| ------ | ---- | ----------- |
|
|
232
|
+
| `getRate(source, target, { apiKey })` | Free | Latest rate for one pair, resolved from the published table |
|
|
233
|
+
| `getLatestRates({ apiKey })` | Free | The tax authority's full latest published table |
|
|
234
|
+
| `getRatesForDate(date, { apiKey, source?, target? })` | Paid | The official table (or one pair) for a YYYY-MM-DD date |
|
|
235
|
+
| `getHistory({ symbol \| source+target, from?, to? }, { apiKey })` | Paid | Daily series since 2021 |
|
|
56
236
|
|
|
57
|
-
##
|
|
237
|
+
## 🔗 Links
|
|
58
238
|
|
|
59
|
-
-
|
|
60
|
-
-
|
|
61
|
-
-
|
|
239
|
+
- [HM Revenue & Customs rates page](https://allratestoday.com/tax-authority-rates-api/hmrc/) — live table, publication cadence, FAQ
|
|
240
|
+
- [All tax authority sources](https://allratestoday.com/tax-authority-rates-api/)
|
|
241
|
+
- [API documentation](https://allratestoday.com/docs/#central-bank) · [Interactive reference](https://allratestoday.com/api-reference/)
|
|
242
|
+
- [Register (free)](https://allratestoday.com/register) · [Pricing](https://allratestoday.com/pricing/)
|
|
243
|
+
- [GitHub](https://github.com/AllRates-Today/hmrc-exchange-rate)
|
|
62
244
|
|
|
63
|
-
## License
|
|
245
|
+
## 📜 License
|
|
64
246
|
|
|
65
247
|
MIT
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@allratestoday/hmrc-exchange-rate",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "Official HM Revenue & Customs (United Kingdom) monthly exchange rates — 141 currencies vs GBP, history since 2021. Zero-dependency Node.js/TypeScript client.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"hmrc",
|