Skip to content

kamaal111/forex-api-daily

Repository files navigation

Forex API daily

Daily European Central Bank web‑scraper that extracts FX rates, computes cross rates, and stores them in Firestore. Exposed as an HTTP Cloud Function (main).

Requirements

  • Node.js 22 (see .nvmrc). If your shell selects a different version, run nvm use.
  • PNPM as the package manager (recommend corepack enable && corepack install).

Setup

pnpm install

Common Commands

  • Build: pnpm compile (TypeScript → index.js).
  • Lint/format: pnpm lint, pnpm format (use pnpm lint --fix to auto‑fix).
  • Start locally: GCP_PROJECT_ID=forex-api-daily pnpm start (Functions Framework on http://localhost:8081/main).
  • Test: pnpm test (runs Vitest; may use Firestore emulator if configured). If you hit PNPM migration issues with lifecycle scripts, run build/lint directly and let us know to update scripts.
  • Start Firestore emulator: pnpm start-db (runs on http://localhost:8080).

How It Works

  • Fetch: Scrapes ECB RSS endpoints to gather daily EUR base rates.
  • Process: Combines latest day’s rates and derives cross rates for other bases.
  • Store: Writes documents to the exchange_rates collection; periodically removes stale dates. After storing new rates, writes the list of available currency symbols to per-date documents under the symbols collection (e.g. symbols/2025-12-05) for efficient client lookups.

Querying Available Symbols

Each run stores a symbols/{YYYY-MM-DD} document (e.g. symbols/2025-12-05) containing the base currency codes available for that date:

{ "date": "2025-12-05", "symbols": ["AUD", "BGN", "BRL", "..."] }

To retrieve the latest available symbols, query the symbols collection ordered by date descending and take the first document:

const snapshot = await db.collection('symbols').orderBy('date', 'desc').limit(1).get();
if (!snapshot.empty) {
  const { date, symbols } = snapshot.docs[0].data();
}

CI/CD

  • GitHub Actions (.github/workflows/ci.yml) runs tests on push. Deploys from main to Cloud Functions using repo secrets for GCP.

Notes

  • Do not commit credentials. Files like .env and service-account.json are ignored by Git.
  • The compiled index.js is generated; avoid committing build artifacts.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors