exchange-rates-uy 1.6.0 → 1.6.1
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 +1 -1
- package/dist/rates/bcu.d.ts +2 -0
- package/dist/rates/bcu.js +10 -1
- package/dist/rates/convert.d.ts +1 -1
- package/dist/rates/convert.js +5 -1
- package/dist/server/sql.js +4 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -287,7 +287,7 @@ let usd = try await rates.history("USD/UYU", from: "2026-01-01")
|
|
|
287
287
|
|
|
288
288
|
```kotlin
|
|
289
289
|
// settings.gradle.kts: repositories { maven("https://jitpack.io") }
|
|
290
|
-
// build.gradle.kts: implementation("com.github.guillecura:exchange-rates-uy:v1.6.
|
|
290
|
+
// build.gradle.kts: implementation("com.github.guillecura:exchange-rates-uy:v1.6.1")
|
|
291
291
|
import uy.exchangerates.RatesClient
|
|
292
292
|
|
|
293
293
|
val rates = RatesClient("https://your-server/api", key = "…") // with a server
|
package/dist/rates/bcu.d.ts
CHANGED
|
@@ -55,6 +55,8 @@ export declare const BCU_QUOTE = "UYU";
|
|
|
55
55
|
* bank quotes joins the official reading the moment it is kept, with no code to
|
|
56
56
|
* change.
|
|
57
57
|
*/
|
|
58
|
+
/** The currencies whose arbitrage the bank publishes as dollars per unit; every other's comes as units per dollar. */
|
|
59
|
+
export declare const ARB_DOLLARS_PER_UNIT: ReadonlySet<string>;
|
|
58
60
|
export declare const BCU_CURRENCIES: Readonly<Record<string, {
|
|
59
61
|
code: number;
|
|
60
62
|
name: string;
|
package/dist/rates/bcu.js
CHANGED
|
@@ -55,6 +55,8 @@ export const BCU_QUOTE = "UYU";
|
|
|
55
55
|
* bank quotes joins the official reading the moment it is kept, with no code to
|
|
56
56
|
* change.
|
|
57
57
|
*/
|
|
58
|
+
/** The currencies whose arbitrage the bank publishes as dollars per unit; every other's comes as units per dollar. */
|
|
59
|
+
export const ARB_DOLLARS_PER_UNIT = new Set(["EUR", "GBP", "AUD", "NZD", "XDR", "UP", "UI"]);
|
|
58
60
|
export const BCU_CURRENCIES = {
|
|
59
61
|
XDR: { code: 2, name: "DER.ESP. DE GIRO" },
|
|
60
62
|
AUD: { code: 105, name: "DOL. AUSTRALIANO" },
|
|
@@ -188,10 +190,17 @@ export async function bcuBetween(from, to, currencies) {
|
|
|
188
190
|
* own figure for that pair and not this module's arithmetic on two of its
|
|
189
191
|
* others: where the two disagree by a hundredth, the published one is the one an
|
|
190
192
|
* invoice will be read against.
|
|
193
|
+
*
|
|
194
|
+
* It comes the way each currency is quoted against the dollar in the market:
|
|
195
|
+
* dollars per unit for the euro, the pound, the Australian and New Zealand
|
|
196
|
+
* dollars, the SDR and the indexed units (`ARB_DOLLARS_PER_UNIT`), units per
|
|
197
|
+
* dollar for every other (1579 pesos argentinos, 5.94 reales). Kept always as
|
|
198
|
+
* dollars per unit, under `ISO/USD`.
|
|
191
199
|
*/
|
|
192
200
|
const arb = Number(tag(block, "ArbAct"));
|
|
193
201
|
if (Number.isFinite(arb) && arb > 0) {
|
|
194
|
-
|
|
202
|
+
const usd = ARB_DOLLARS_PER_UNIT.has(currency.iso) ? arb : 1 / arb;
|
|
203
|
+
reading.published[`${currency.iso}/USD`] = { buy: usd, sell: usd };
|
|
195
204
|
}
|
|
196
205
|
}
|
|
197
206
|
return [...byDay.entries()]
|
package/dist/rates/convert.d.ts
CHANGED
|
@@ -13,7 +13,7 @@ export interface Spread {
|
|
|
13
13
|
/**
|
|
14
14
|
* The official rate for one `base` in `quote`, out of the bank's reading.
|
|
15
15
|
*
|
|
16
|
-
* What the bank published already divided wins (`published`, keyed `BASE/QUOTE`).
|
|
16
|
+
* What the bank published already divided wins (`published`, keyed `BASE/QUOTE`), either way round.
|
|
17
17
|
* Otherwise it is one division through the peso, which the bank quotes everything
|
|
18
18
|
* against: the base's pesos over the quote's. Buying and selling stay on their own
|
|
19
19
|
* sides of the division, so the spread of a derived pair is the two spreads
|
package/dist/rates/convert.js
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
/**
|
|
9
9
|
* The official rate for one `base` in `quote`, out of the bank's reading.
|
|
10
10
|
*
|
|
11
|
-
* What the bank published already divided wins (`published`, keyed `BASE/QUOTE`).
|
|
11
|
+
* What the bank published already divided wins (`published`, keyed `BASE/QUOTE`), either way round.
|
|
12
12
|
* Otherwise it is one division through the peso, which the bank quotes everything
|
|
13
13
|
* against: the base's pesos over the quote's. Buying and selling stay on their own
|
|
14
14
|
* sides of the division, so the spread of a derived pair is the two spreads
|
|
@@ -19,6 +19,10 @@ export function officialCross(perLocal, published, base, quote) {
|
|
|
19
19
|
const direct = published[`${base}/${quote}`];
|
|
20
20
|
if (direct)
|
|
21
21
|
return direct;
|
|
22
|
+
// The same pair the other way round: the bank's selling price becomes the buying one.
|
|
23
|
+
const reverse = published[`${quote}/${base}`];
|
|
24
|
+
if (reverse && reverse.buy > 0 && reverse.sell > 0)
|
|
25
|
+
return { buy: 1 / reverse.sell, sell: 1 / reverse.buy };
|
|
22
26
|
const from = perLocal[base];
|
|
23
27
|
const to = perLocal[quote];
|
|
24
28
|
if (!from || !to)
|
package/dist/server/sql.js
CHANGED
|
@@ -67,6 +67,10 @@ export const MIGRATIONS = [
|
|
|
67
67
|
`create index if not exists {log}_at on {log} (at)`,
|
|
68
68
|
// Whose table a market day is: 'live' (ExchangeRate-API, read on its day) or 'past' (a day gone by, filled in).
|
|
69
69
|
`alter table {market} add column source text not null default 'live'`,
|
|
70
|
+
// Until 1.6.1 a currency's arbitrage was kept as the bank sent it, which is units per dollar for all but these:
|
|
71
|
+
// kept from now on as dollars per unit, as `usd` always said.
|
|
72
|
+
`update {official} set usd = 1.0 / usd
|
|
73
|
+
where usd is not null and usd > 0 and iso not in ('USD', 'EUR', 'GBP', 'AUD', 'NZD', 'XDR', 'UP', 'UI')`,
|
|
70
74
|
];
|
|
71
75
|
/** Brings a database up to the last entry of `MIGRATIONS`. Safe to call on every start. */
|
|
72
76
|
export async function migrate(sql) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "exchange-rates-uy",
|
|
3
|
-
"version": "1.6.
|
|
3
|
+
"version": "1.6.1",
|
|
4
4
|
"description": "Uruguay's exchange rates, self-hosted: the official one (Banco Central del Uruguay) and the market's, any pair, customizable pairs and schedule, an API, a public page and a panel. Any backend: SQLite, Postgres (Supabase, Neon, Vercel, RDS), Cloudflare D1; Node, Workers, Lambda, Vercel, Deno, Bun.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"android",
|