bna-exchange-rate 1.2.7
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/LICENSE +21 -0
- package/README.md +251 -0
- package/index.cjs +47 -0
- package/index.d.ts +52 -0
- package/index.mjs +44 -0
- package/package.json +55 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 AllRatesToday (https://allratestoday.com)
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
# National Bank of Angola Exchange Rate API โ bna-exchange-rate
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/bna-exchange-rate)
|
|
4
|
+
[](https://github.com/AllRates-Today/bna-exchange-rate/blob/main/LICENSE)
|
|
5
|
+
[](https://www.npmjs.com/package/bna-exchange-rate)
|
|
6
|
+
[](https://www.typescriptlang.org/)
|
|
7
|
+
|
|
8
|
+
**Official National Bank of Angola (Angola) daily exchange rates for Node.js and TypeScript. The published central bank rates behind tax filings, customs valuations, audits, and compliant invoicing โ not market estimates, but the numbers National Bank of Angola itself prints, every business day.**
|
|
9
|
+
|
|
10
|
+
## ๐ Why this client?
|
|
11
|
+
|
|
12
|
+
- ๐๏ธ **Official published rates** โ National Bank of Angola's own table, with the publisher's own `rate_date` on every response
|
|
13
|
+
- ๐
**History back to 1999** โ 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
|
+
> **Official rate, not mid-market:** every value here is a number National Bank of Angola itself published, fixed once printed and carrying the central bank's own `rate_date` โ what filings and audits require. Need the live interbank midpoint for pricing or display instead? Use the [mid-market API](https://allratestoday.com/docs/) or [`@allratestoday/sdk`](https://www.npmjs.com/package/@allratestoday/sdk). The two can diverge by several percent.
|
|
20
|
+
|
|
21
|
+
## ๐ Get your API key
|
|
22
|
+
|
|
23
|
+
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.
|
|
24
|
+
|
|
25
|
+
## ๐ฆ Installation
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
npm install bna-exchange-rate
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
yarn add bna-exchange-rate
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
pnpm add bna-exchange-rate
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
Also published under the org scope as [`@allratestoday/bna-exchange-rate`](https://www.npmjs.com/package/@allratestoday/bna-exchange-rate) โ same code, same versions.
|
|
40
|
+
|
|
41
|
+
## ๐ Quick start
|
|
42
|
+
|
|
43
|
+
```js
|
|
44
|
+
import { getRate } from 'bna-exchange-rate';
|
|
45
|
+
|
|
46
|
+
const pair = await getRate('USD', 'AOA', { apiKey: 'art_live_...' });
|
|
47
|
+
console.log(pair.rate, pair.rate_date); // the official National Bank of Angola rate, on the central bank's own date
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## ๐ API reference
|
|
51
|
+
|
|
52
|
+
- [Latest pair rate](#latest-pair-rate) โ one pair from the latest published table
|
|
53
|
+
- [Full published table](#full-published-table) โ everything the central bank printed, in one call
|
|
54
|
+
- [Table for a date](#table-for-a-date) โ the official table for an invoice or filing date
|
|
55
|
+
- [Daily time series](#daily-time-series) โ one pair across a date range
|
|
56
|
+
|
|
57
|
+
---
|
|
58
|
+
|
|
59
|
+
### Latest pair rate
|
|
60
|
+
|
|
61
|
+
Free plan and up. Pairs the central bank does not print directly are resolved from its table and flagged (see *Published vs derived rates* below).
|
|
62
|
+
|
|
63
|
+
```js
|
|
64
|
+
const pair = await getRate('USD', 'AOA', { apiKey: 'art_live_...' });
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
**Response:**
|
|
68
|
+
|
|
69
|
+
```javascript
|
|
70
|
+
{
|
|
71
|
+
bank: 'bna',
|
|
72
|
+
name: 'National Bank of Angola',
|
|
73
|
+
rate_date: '2026-08-21', // National Bank of Angola's own publication date
|
|
74
|
+
source: 'USD',
|
|
75
|
+
target: 'AOA',
|
|
76
|
+
rate: 912.799,
|
|
77
|
+
rate_type: 'reference',
|
|
78
|
+
derived: false,
|
|
79
|
+
method: 'published',
|
|
80
|
+
disclaimer: 'โฆ'
|
|
81
|
+
}
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
### Full published table
|
|
85
|
+
|
|
86
|
+
Free plan and up. The complete table for the latest publication date.
|
|
87
|
+
|
|
88
|
+
```js
|
|
89
|
+
import { getLatestRates } from 'bna-exchange-rate';
|
|
90
|
+
|
|
91
|
+
const table = await getLatestRates({ apiKey: 'art_live_...' });
|
|
92
|
+
console.log(table.rate_date, table.rates.length);
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
**Response:**
|
|
96
|
+
|
|
97
|
+
```javascript
|
|
98
|
+
{
|
|
99
|
+
bank: 'bna',
|
|
100
|
+
name: 'National Bank of Angola',
|
|
101
|
+
rate_date: '2026-08-21',
|
|
102
|
+
rates: [
|
|
103
|
+
{ "base": "USD", "quote": "AOA", "type": "reference", "value": 912.799 },
|
|
104
|
+
{ "base": "USD", "quote": "AOA", "type": "sell", "value": 912.799 },
|
|
105
|
+
{ "base": "USD", "quote": "AOA", "type": "buy", "value": 912.799 },
|
|
106
|
+
// โฆ the rest of the published table (70 currencies vs AOA)
|
|
107
|
+
],
|
|
108
|
+
disclaimer: 'โฆ'
|
|
109
|
+
}
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
### Table for a date
|
|
113
|
+
|
|
114
|
+
Paid plans. The official table for any date since 1999 โ 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.
|
|
115
|
+
|
|
116
|
+
```js
|
|
117
|
+
import { getRatesForDate } from 'bna-exchange-rate';
|
|
118
|
+
|
|
119
|
+
const day = await getRatesForDate('2026-06-30', { apiKey: 'art_live_...' });
|
|
120
|
+
// Optionally narrow to one pair:
|
|
121
|
+
const one = await getRatesForDate('2026-06-30', { apiKey: 'art_live_...', source: 'USD', target: 'AOA' });
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
**Response:**
|
|
125
|
+
|
|
126
|
+
```javascript
|
|
127
|
+
{
|
|
128
|
+
bank: 'bna',
|
|
129
|
+
requested_date: '2026-06-30',
|
|
130
|
+
rate_date: '2026-06-30', // the date actually published
|
|
131
|
+
published_on_requested_date: true, // false when a weekend/holiday fell back
|
|
132
|
+
rates: [ /* the full table for that date */ ],
|
|
133
|
+
disclaimer: 'โฆ'
|
|
134
|
+
}
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
### Daily time series
|
|
138
|
+
|
|
139
|
+
Paid plans. One resolved rate per publication date โ ready for charting, revaluation runs, or audit workpapers.
|
|
140
|
+
|
|
141
|
+
```js
|
|
142
|
+
import { getHistory } from 'bna-exchange-rate';
|
|
143
|
+
|
|
144
|
+
const series = await getHistory(
|
|
145
|
+
{ source: 'USD', target: 'AOA', from: '2026-01-01', to: '2026-08-21' },
|
|
146
|
+
{ apiKey: 'art_live_...' }
|
|
147
|
+
);
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
**Response:**
|
|
151
|
+
|
|
152
|
+
```javascript
|
|
153
|
+
{
|
|
154
|
+
bank: 'bna',
|
|
155
|
+
source: 'USD',
|
|
156
|
+
target: 'AOA',
|
|
157
|
+
from: '2026-01-01',
|
|
158
|
+
to: '2026-08-21',
|
|
159
|
+
count: 152,
|
|
160
|
+
rates: [
|
|
161
|
+
// one entry per publication date
|
|
162
|
+
{ date: '2026-08-21', rate: 912.799, rate_type: 'reference', derived: false, method: 'published' },
|
|
163
|
+
// โฆ
|
|
164
|
+
],
|
|
165
|
+
disclaimer: 'โฆ'
|
|
166
|
+
}
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
Pass `{ symbol: 'USD' }` instead of `source`/`target` to get the raw published rows for one currency (all rate types, no pair resolution).
|
|
170
|
+
|
|
171
|
+
---
|
|
172
|
+
|
|
173
|
+
## ๐บ๏ธ Currencies covered
|
|
174
|
+
|
|
175
|
+
National Bank of Angola currently publishes rates covering **70 currencies** against the AOA (as of the latest table):
|
|
176
|
+
|
|
177
|
+
๐ฆ๐ช `AED` ยท ๐ฆ๐ฑ `ALL` ยท ๐ฆ๐ท `ARS` ยท ๐ฆ๐บ `AUD` ยท ๐ง๐ฌ `BGN` ยท ๐ง๐ฒ `BMD` ยท ๐ง๐ด `BOB` ยท ๐ง๐ท `BRL` ยท ๐ง๐ธ `BSD` ยท ๐ง๐ผ `BWP` ยท ๐จ๐ฆ `CAD` ยท ๐จ๐ฉ `CDF` ยท ๐จ๐ญ `CHF` ยท ๐จ๐ณ `CNY` ยท ๐จ๐ท `CRC` ยท ๐จ๐บ `CUP` ยท ๐จ๐ป `CVE` ยท ๐จ๐ฟ `CZK` ยท ๐ฉ๐ฐ `DKK` ยท ๐ช๐ช `EEK` ยท ๐ช๐ฌ `EGP` ยท ๐ช๐น `ETB` ยท ๐ช๐บ `EUR` ยท ๐ฌ๐ง `GBP` ยท ๐ญ๐ฐ `HKD` ยท ๐ญ๐ท `HRK` ยท ๐ญ๐บ `HUF` ยท ๐ฎ๐ฉ `IDR` ยท ๐ฎ๐ฑ `ILS` ยท ๐ฎ๐ณ `INR` ยท ๐ฎ๐ถ `IQD` ยท ๐ฏ๐ฒ `JMD` ยท ๐ฏ๐ต `JPY` ยท ๐ฐ๐ช `KES` ยท ๐ฐ๐ท `KRW` ยท ๐ฐ๐ผ `KWD` ยท ๐ฐ๐ฟ `KZT` ยท ๐ฑ๐ง `LBP` ยท ๐ฑ๐ฐ `LKR` ยท ๐ฑ๐ธ `LSL` ยท ๐ฒ๐ฆ `MAD` ยท ๐ฒ๐ฝ `MXN` ยท ๐ฒ๐พ `MYR` ยท ๐ฒ๐ฟ `MZN` ยท ๐ณ๐ฆ `NAD` ยท ๐ณ๐ฌ `NGN` ยท ๐ณ๐ด `NOK` ยท ๐ณ๐ฟ `NZD` ยท ๐ต๐ช `PEN` ยท ๐ต๐ฐ `PKR` ยท ๐ต๐ฑ `PLN` ยท ๐ถ๐ฆ `QAR` ยท ๐ท๐ด `RON` ยท ๐ท๐บ `RUB` ยท ๐ธ๐ฆ `SAR` ยท ๐ธ๐ช `SEK` ยท ๐ธ๐ฌ `SGD` ยท ๐ธ๐น `STD` ยท ๐น๐ญ `THB` ยท ๐น๐น `TTD` ยท ๐น๐ผ `TWD` ยท ๐น๐ฟ `TZS` ยท ๐บ๐ฆ `UAH` ยท ๐บ๐ธ `USD` ยท ๐ป๐ช `VEF` ยท ๐ป๐ณ `VND` ยท `XAF` ยท `XAU` ยท ๐ฟ๐ฆ `ZAR` ยท ๐ฟ๐ฒ `ZMK`
|
|
178
|
+
|
|
179
|
+
## โ๏ธ Published vs derived rates
|
|
180
|
+
|
|
181
|
+
If National Bank of Angola does not print a pair directly, the API resolves it from the central bank's own table and says so โ official and computed values are never confused:
|
|
182
|
+
|
|
183
|
+
| `method` | `derived` | Meaning |
|
|
184
|
+
| --- | --- | --- |
|
|
185
|
+
| `published` | `false` | The central bank printed this pair directly |
|
|
186
|
+
| `inverse` | `true` | Computed as 1 รท the published opposite direction |
|
|
187
|
+
| `cross` | `true` | Computed via AOA from two published rates |
|
|
188
|
+
|
|
189
|
+
## ๐ก๏ธ Error handling
|
|
190
|
+
|
|
191
|
+
Errors are thrown as `Error` with `status` (HTTP code) and `body` (the API's JSON error) attached:
|
|
192
|
+
|
|
193
|
+
```js
|
|
194
|
+
try {
|
|
195
|
+
const pair = await getRate('USD', 'XXX', { apiKey: 'art_live_...' });
|
|
196
|
+
} catch (err) {
|
|
197
|
+
console.log(err.message); // human-readable reason
|
|
198
|
+
console.log(err.status); // e.g. 404
|
|
199
|
+
}
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
| Status | Meaning |
|
|
203
|
+
| ------ | ------- |
|
|
204
|
+
| โ | Missing `apiKey` (thrown before any request) |
|
|
205
|
+
| `400` | Malformed date or parameters |
|
|
206
|
+
| `401` | Invalid API key |
|
|
207
|
+
| `403` | Endpoint needs a [paid plan](https://allratestoday.com/pricing/) (historical dates & series) |
|
|
208
|
+
| `404` | Pair or date range not covered by National Bank of Angola |
|
|
209
|
+
| `429` | Monthly quota exceeded |
|
|
210
|
+
|
|
211
|
+
## ๐ท TypeScript
|
|
212
|
+
|
|
213
|
+
Full definitions ship with the package โ no `@types` install:
|
|
214
|
+
|
|
215
|
+
```ts
|
|
216
|
+
import type { LatestRates, PairRate, DatedRates, RateEntry, HistoryQuery, RequestOptions } from 'bna-exchange-rate';
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
## ๐ฆ CommonJS
|
|
220
|
+
|
|
221
|
+
```javascript
|
|
222
|
+
const { getRate } = require('bna-exchange-rate');
|
|
223
|
+
|
|
224
|
+
getRate('USD', 'AOA', { apiKey: 'art_live_...' }).then((pair) => console.log(pair.rate));
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
## ๐ก Quota tips
|
|
228
|
+
|
|
229
|
+
- Rates change once per business day โ cache the published table locally and a small monthly quota goes a long way.
|
|
230
|
+
- Every request counts toward your AllRatesToday quota, shared across all AllRatesToday endpoints on your key.
|
|
231
|
+
|
|
232
|
+
## ๐ Methods reference
|
|
233
|
+
|
|
234
|
+
| Method | Plan | Description |
|
|
235
|
+
| ------ | ---- | ----------- |
|
|
236
|
+
| `getRate(source, target, { apiKey })` | Free | Latest rate for one pair, resolved from the published table |
|
|
237
|
+
| `getLatestRates({ apiKey })` | Free | The central bank's full latest published table |
|
|
238
|
+
| `getRatesForDate(date, { apiKey, source?, target? })` | Paid | The official table (or one pair) for a YYYY-MM-DD date |
|
|
239
|
+
| `getHistory({ symbol \| source+target, from?, to? }, { apiKey })` | Paid | Daily series since 1999 |
|
|
240
|
+
|
|
241
|
+
## ๐ Links
|
|
242
|
+
|
|
243
|
+
- [National Bank of Angola rates page](https://allratestoday.com/central-bank-rates-api/bna/) โ live table, publication cadence, FAQ
|
|
244
|
+
- [All central bank sources](https://allratestoday.com/central-bank-rates-api/)
|
|
245
|
+
- [API documentation](https://allratestoday.com/docs/#central-bank) ยท [Interactive reference](https://allratestoday.com/api-reference/)
|
|
246
|
+
- [Register (free)](https://allratestoday.com/register) ยท [Pricing](https://allratestoday.com/pricing/)
|
|
247
|
+
- [GitHub](https://github.com/AllRates-Today/bna-exchange-rate)
|
|
248
|
+
|
|
249
|
+
## ๐ License
|
|
250
|
+
|
|
251
|
+
MIT
|
package/index.cjs
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
// National Bank of Angola exchange rates via the AllRatesToday API.
|
|
3
|
+
const BASE = 'https://allratestoday.com/api/v1/central-bank/bna';
|
|
4
|
+
const KEY_HINT = 'An apiKey is required โ get a free key at https://allratestoday.com/register (no credit card required).';
|
|
5
|
+
|
|
6
|
+
async function request(path, params, options) {
|
|
7
|
+
const apiKey = options && options.apiKey;
|
|
8
|
+
if (!apiKey) throw new Error(KEY_HINT);
|
|
9
|
+
const url = new URL(BASE + path);
|
|
10
|
+
for (const [k, v] of Object.entries(params || {})) {
|
|
11
|
+
if (v !== undefined && v !== null) url.searchParams.set(k, v);
|
|
12
|
+
}
|
|
13
|
+
const res = await fetch(url, { headers: { Authorization: 'Bearer ' + apiKey } });
|
|
14
|
+
let body;
|
|
15
|
+
try { body = await res.json(); } catch { body = {}; }
|
|
16
|
+
if (!res.ok) {
|
|
17
|
+
const err = new Error(body.error || ('Request failed: HTTP ' + res.status));
|
|
18
|
+
err.status = res.status;
|
|
19
|
+
err.body = body;
|
|
20
|
+
throw err;
|
|
21
|
+
}
|
|
22
|
+
return body;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** Latest published table (all plans, including free). */
|
|
26
|
+
async function getLatestRates(options) {
|
|
27
|
+
return request('/latest', {}, options);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** Latest rate for one pair, e.g. getRate('USD', 'AOA', { apiKey }). */
|
|
31
|
+
async function getRate(source, target, options) {
|
|
32
|
+
return request('/latest', { source, target }, options);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** Published table for a date (YYYY-MM-DD). Paid plans. Weekends/holidays return the most recent published date. */
|
|
36
|
+
async function getRatesForDate(date, options) {
|
|
37
|
+
if (!/^\d{4}-\d{2}-\d{2}$/.test(String(date))) throw new Error('date must be YYYY-MM-DD');
|
|
38
|
+
return request('/' + date, options && options.source ? { source: options.source, target: options.target } : {}, options);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** Daily time series. Pass { symbol } or { source, target }, optional from/to (YYYY-MM-DD). Paid plans. */
|
|
42
|
+
async function getHistory(query, options) {
|
|
43
|
+
const { symbol, source, target, from, to } = query || {};
|
|
44
|
+
return request('/history', { symbol, source, target, from, to }, options);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
module.exports = { getLatestRates, getRate, getRatesForDate, getHistory };
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
export interface RequestOptions {
|
|
2
|
+
/** AllRatesToday API key โ free at https://allratestoday.com/register */
|
|
3
|
+
apiKey: string;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
export interface RateEntry {
|
|
7
|
+
base: string;
|
|
8
|
+
quote: string;
|
|
9
|
+
type: string;
|
|
10
|
+
value: number;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface LatestRates {
|
|
14
|
+
bank: 'bna';
|
|
15
|
+
name: string;
|
|
16
|
+
rate_date: string;
|
|
17
|
+
rates: RateEntry[];
|
|
18
|
+
disclaimer: string;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface PairRate {
|
|
22
|
+
bank: 'bna';
|
|
23
|
+
name: string;
|
|
24
|
+
rate_date: string;
|
|
25
|
+
source: string;
|
|
26
|
+
target: string;
|
|
27
|
+
rate: number;
|
|
28
|
+
rate_type: string;
|
|
29
|
+
/** true when the pair was computed (inverse/cross) rather than published directly */
|
|
30
|
+
derived: boolean;
|
|
31
|
+
method: 'published' | 'inverse' | 'cross';
|
|
32
|
+
disclaimer: string;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export interface DatedRates extends Omit<LatestRates, 'rate_date'> {
|
|
36
|
+
requested_date: string;
|
|
37
|
+
rate_date: string;
|
|
38
|
+
published_on_requested_date: boolean;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export interface HistoryQuery {
|
|
42
|
+
symbol?: string;
|
|
43
|
+
source?: string;
|
|
44
|
+
target?: string;
|
|
45
|
+
from?: string;
|
|
46
|
+
to?: string;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export declare function getLatestRates(options: RequestOptions): Promise<LatestRates>;
|
|
50
|
+
export declare function getRate(source: string, target: string, options: RequestOptions): Promise<PairRate>;
|
|
51
|
+
export declare function getRatesForDate(date: string, options: RequestOptions & { source?: string; target?: string }): Promise<DatedRates>;
|
|
52
|
+
export declare function getHistory(query: HistoryQuery, options: RequestOptions): Promise<unknown>;
|
package/index.mjs
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
// National Bank of Angola exchange rates via the AllRatesToday API.
|
|
2
|
+
const BASE = 'https://allratestoday.com/api/v1/central-bank/bna';
|
|
3
|
+
const KEY_HINT = 'An apiKey is required โ get a free key at https://allratestoday.com/register (no credit card required).';
|
|
4
|
+
|
|
5
|
+
async function request(path, params, options) {
|
|
6
|
+
const apiKey = options && options.apiKey;
|
|
7
|
+
if (!apiKey) throw new Error(KEY_HINT);
|
|
8
|
+
const url = new URL(BASE + path);
|
|
9
|
+
for (const [k, v] of Object.entries(params || {})) {
|
|
10
|
+
if (v !== undefined && v !== null) url.searchParams.set(k, v);
|
|
11
|
+
}
|
|
12
|
+
const res = await fetch(url, { headers: { Authorization: 'Bearer ' + apiKey } });
|
|
13
|
+
let body;
|
|
14
|
+
try { body = await res.json(); } catch { body = {}; }
|
|
15
|
+
if (!res.ok) {
|
|
16
|
+
const err = new Error(body.error || ('Request failed: HTTP ' + res.status));
|
|
17
|
+
err.status = res.status;
|
|
18
|
+
err.body = body;
|
|
19
|
+
throw err;
|
|
20
|
+
}
|
|
21
|
+
return body;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** Latest published table (all plans, including free). */
|
|
25
|
+
export async function getLatestRates(options) {
|
|
26
|
+
return request('/latest', {}, options);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** Latest rate for one pair, e.g. getRate('USD', 'AOA', { apiKey }). */
|
|
30
|
+
export async function getRate(source, target, options) {
|
|
31
|
+
return request('/latest', { source, target }, options);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** Published table for a date (YYYY-MM-DD). Paid plans. Weekends/holidays return the most recent published date. */
|
|
35
|
+
export async function getRatesForDate(date, options) {
|
|
36
|
+
if (!/^\d{4}-\d{2}-\d{2}$/.test(String(date))) throw new Error('date must be YYYY-MM-DD');
|
|
37
|
+
return request('/' + date, options && options.source ? { source: options.source, target: options.target } : {}, options);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** Daily time series. Pass { symbol } or { source, target }, optional from/to (YYYY-MM-DD). Paid plans. */
|
|
41
|
+
export async function getHistory(query, options) {
|
|
42
|
+
const { symbol, source, target, from, to } = query || {};
|
|
43
|
+
return request('/history', { symbol, source, target, from, to }, options);
|
|
44
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "bna-exchange-rate",
|
|
3
|
+
"version": "1.2.7",
|
|
4
|
+
"description": "Official National Bank of Angola (Angola) daily exchange rates โ 70 currencies vs AOA, history since 1999. Zero-dependency Node.js/TypeScript client.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"bna",
|
|
7
|
+
"national",
|
|
8
|
+
"bank",
|
|
9
|
+
"of",
|
|
10
|
+
"angola",
|
|
11
|
+
"exchange-rate",
|
|
12
|
+
"exchange-rates",
|
|
13
|
+
"currency",
|
|
14
|
+
"forex",
|
|
15
|
+
"fx",
|
|
16
|
+
"aoa",
|
|
17
|
+
"central-bank",
|
|
18
|
+
"official-rates",
|
|
19
|
+
"angola",
|
|
20
|
+
"api",
|
|
21
|
+
"typescript"
|
|
22
|
+
],
|
|
23
|
+
"homepage": "https://allratestoday.com/central-bank-rates-api/bna/",
|
|
24
|
+
"repository": {
|
|
25
|
+
"type": "git",
|
|
26
|
+
"url": "git+https://github.com/AllRates-Today/bna-exchange-rate.git"
|
|
27
|
+
},
|
|
28
|
+
"bugs": {
|
|
29
|
+
"url": "https://github.com/AllRates-Today/bna-exchange-rate/issues"
|
|
30
|
+
},
|
|
31
|
+
"license": "MIT",
|
|
32
|
+
"author": "AllRatesToday <hello@allratestoday.com> (https://allratestoday.com)",
|
|
33
|
+
"type": "module",
|
|
34
|
+
"main": "./index.cjs",
|
|
35
|
+
"module": "./index.mjs",
|
|
36
|
+
"types": "./index.d.ts",
|
|
37
|
+
"exports": {
|
|
38
|
+
".": {
|
|
39
|
+
"types": "./index.d.ts",
|
|
40
|
+
"import": "./index.mjs",
|
|
41
|
+
"require": "./index.cjs"
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
"files": [
|
|
45
|
+
"index.mjs",
|
|
46
|
+
"index.cjs",
|
|
47
|
+
"index.d.ts",
|
|
48
|
+
"README.md",
|
|
49
|
+
"LICENSE"
|
|
50
|
+
],
|
|
51
|
+
"engines": {
|
|
52
|
+
"node": ">=18"
|
|
53
|
+
},
|
|
54
|
+
"sideEffects": false
|
|
55
|
+
}
|