MIT · TypeScript · version 1.8.2
exchange-rates-uy
Uruguay’s exchange rates on your own backend. The BCU’s official rate and the market’s.
$ npm install exchange-rates-uy- 2
- sources: BCU and the market
- 34
- currencies the BCU quotes
- 3
- databases: SQLite, Postgres, D1
- 3
- clients: JS, Swift, Kotlin
Quick start
- 01
npx exchange-rates-uy serveA server on SQLite: the page at /, the API at /api, the panel at /admin with ADMIN_TOKEN.
- 02
RATES_PAIRS=USD/UYU,EUR/UYUThe currencies and pairs to start with; after that, the panel adds, retires and orders them.
- 03
createRatesClient({ baseUrl })In your app: JS, Swift or Kotlin. Without a server, it reads the BCU and the market itself.
The server
A Node process, a container, a Worker or a function, on the database you already have.
server.ts
import { serve } from "exchange-rates-uy/node";
await serve({ port: 8787, database: "./rates.db", adminToken: process.env.ADMIN_TOKEN });
// or on Postgres
import pg from "pg";
import { pgSql } from "exchange-rates-uy/postgres";
await serve({ sql: pgSql(new pg.Pool({ connectionString: process.env.DATABASE_URL })) });The apps
The same calls in the three: with your server’s address, or with nothing and the pairs you want.
rates.ts
import { createRatesClient } from "exchange-rates-uy/client";
const rates = createRatesClient({ baseUrl: "https://your-server/api", key: process.env.RATES_API_KEY }); // with a server
const alone = createRatesClient({ pairs: ["USD/UYU", "EUR/UYU"] }); // without one
const bank = await rates.official(); // the BCU's pesos per unit, buying and selling
const usd = await rates.history("USD/UYU", { from: "2026-01-01" });
await rates.convert({ amount: 100, from: "USD", to: "UYU", source: "official" });Where it runs
| Platform | Clock | Import |
|---|---|---|
| Node 22.13+ · Docker | its own timer | exchange-rates-uy/node |
| Cloudflare Workers | a Cron Trigger | exchange-rates-uy/worker |
| AWS Lambda | EventBridge | exchange-rates-uy/lambda |
| Supabase · Vercel · Deno · Bun | pg_cron, Vercel Cron: /api/tick | exchange-rates-uy/server |
Rates are kept in SQLite, Postgres (Supabase, Neon, Vercel, RDS) or Cloudflare D1.
What it takes care of
Each slot read once
A slot is claimed in the database before it is read: restarts, several instances or a late trigger never read twice, and one missed while down is read on the next tick.
Any pair
Official: what the BCU published, else through the peso with both spreads compounded. Market: one column over another. Computed when asked, so a new pair has its history at once.
The market’s past
The free table is only today’s, so the package ships an archive: every currency against the dollar, daily since March 2024, public domain, a new month each month.
Fits a free D1
A public request only reads. The past is kept only for your pairs’ currencies, and the indexes are built by the ticks under the daily write limit.
Who may read the API
Open by default. With access: the origins you list, the server’s own page, and server callers with a key, compared in constant time.
Rates as people read them
Four digits that mean something (40.08, 0.0256, 1592), and money with its code, because $ alone says nothing.
Why
They answer two questions. The official rate is what an invoice or a tax return is read against: the BCU publishes it once a working day, buying and selling. The market rate is what the rest of the world uses: one number for every currency, every day. The package keeps both and never averages them, since that average is true nowhere.
The BCU doesn’t let another site call it from a browser, and the market’s free table is only today’s. So a server reads them on a schedule, keeps what they said, and your apps ask it.
Without
- API keys or accounts: both sources are free
- A database or a host of its own
- Dependencies
rates.whitebear.io runs on it, and it keeps the rates for Whitebear’s products and for Umino.