Foreign Currency Revaluation: How to Snapshot Month-End Exchange Rates

6 min read

Foreign Currency Revaluation: How to Snapshot Month-End Exchange Rates

Foreign currency revaluation is the month-end step where you restate open foreign-currency balances (receivables, payables, bank accounts) at the exchange rate on the closing date. To do it, you need exactly one rate per currency, captured at a defined moment, stored so nobody can quietly change it later.

The calculation is easy. The hard part is the data: which rate, captured when, from where, and how you prove it in an audit. This article covers what a revaluation snapshot should contain, how to automate it, and what to do when the rate you get is stale or derived.

What foreign currency revaluation actually needs

Say your reporting currency is USD and you hold a EUR 10,000 receivable. You booked it when you issued the invoice, at an example rate of 1.0800, so the ledger shows USD 10,800.00. At month-end the rate is, in this example, 1.0842:

ItemCalculationResult
Booked value10,000 × 1.0800USD 10,800.00
Closing value10,000 × 1.0842USD 10,842.00
Unrealized difference10,842.00 − 10,800.00USD 42.00

The EUR amount never changed. Only its value in your reporting currency did. The 42.00 goes to an unrealized gain or loss account, and many teams reverse it on the first day of the next period. Your accountant and your accounting policy decide the exact treatment. Your job as the developer is to supply the closing rate reliably.

Every revaluation run needs:

  • A list of the currencies with open balances.
  • One closing rate per currency pair, in a consistent direction (1 unit of foreign currency = N units of reporting currency).
  • The timestamp of that rate, so you can show when it was observed.
  • A frozen copy of all of it, tied to the period.

For the transaction-time side of this, see how to invoice in a foreign currency. Revaluation is the same discipline applied at period end.

Decide your rate policy first

Before writing code, write down the policy. Auditors care less about which source you chose than about whether you applied it consistently.

  • Cutoff time. For example, "23:59 UTC on the last calendar day" or "the first run after midnight UTC". Pick one and document it.
  • Source. A market-data API gives you a market rate. If your jurisdiction or auditor requires a specific official fixing, confirm that a market-data rate is acceptable. GetRatesAPI does not provide bank or central-bank fixing rates, so don't promise that in your policy if you rely on it.
  • Direction and precision. Store the rate exactly as received. Don't invert it and round it; invert only at calculation time, if needed.
  • Fallback. What happens if the job fails at the cutoff? Decide in advance who can approve a rerun and how it is logged.

One honest limitation: GetRatesAPI returns current rates, not historical ones. That means the snapshot must be taken by you, at close, and stored in your own database. If you miss the cutoff, you can't backfill the exact moment later. That is a reason to schedule the job with some redundancy, not a reason to avoid automation.

What to store with each closing rate

A bare number isn't enough. Each current-rate response carries fields that belong in your snapshot table:

{"base":"EUR","quote":"USD","rate":"1.0842","as_of":"2026-01-02T10:00:00Z","status":"fresh","type":"direct"}

Store these columns:

ColumnWhy
period (for example 2026-10)Ties the rate to the close it served
base, quoteThe pair and its direction
rate (text or DECIMAL)Exact string, never a float
as_ofWhen the market observation happened
statusWhether the rate was fresh when you captured it
typeDirect or derived, useful when explaining where a rate came from
captured_atWhen your job ran, which can differ from as_of

Make the table append-only, with a unique key on (period, base, quote). A correction should be a new, reviewed row or a new version, not an update in place.

Keep as_of and captured_at separate. A derived rate's as_of is the age of its oldest input, so it can be slightly earlier than the moment you asked. Both facts are useful.

A month-end snapshot job in Python

This script reads the currencies with open balances, fetches each pair against your reporting currency, and inserts the results. It uses Decimal and stores rates as text. It reads the key from an environment variable.

import os
import sqlite3
from datetime import datetime, timezone

import requests

API = "https://api.getratesapi.com"
REPORTING = "USD"
PERIOD = "2026-10"
HEADERS = {"Authorization": f"ApiKey {os.environ['GETRATES_API_KEY']}"}


def fetch_rate(base: str, quote: str) -> dict:
    resp = requests.get(
        f"{API}/v1/rates/{base}/{quote}", headers=HEADERS, timeout=10
    )
    resp.raise_for_status()
    return resp.json()


def snapshot(db: sqlite3.Connection, currencies: list[str]) -> list[str]:
    needs_review = []
    for code in currencies:
        if code == REPORTING:
            continue
        data = fetch_rate(code, REPORTING)
        if data["status"] != "fresh":
            needs_review.append(code)
        db.execute(
            """INSERT OR IGNORE INTO closing_rates
               (period, base, quote, rate, as_of, status, type, captured_at)
               VALUES (?, ?, ?, ?, ?, ?, ?, ?)""",
            (
                PERIOD, data["base"], data["quote"], data["rate"],
                data["as_of"], data["status"], data["type"],
                datetime.now(timezone.utc).isoformat(),
            ),
        )
    db.commit()
    return needs_review


if __name__ == "__main__":
    db = sqlite3.connect("ledger.db")
    db.execute(
        """CREATE TABLE IF NOT EXISTS closing_rates (
             period TEXT, base TEXT, quote TEXT, rate TEXT,
             as_of TEXT, status TEXT, type TEXT, captured_at TEXT,
             UNIQUE (period, base, quote))"""
    )
    flagged = snapshot(db, ["EUR", "GBP", "JPY", "CHF"])
    if flagged:
        print("Review stale rates:", flagged)

Then revalue with exact arithmetic, rounding only once at the end. See currency decimal places for choosing the right number of digits.

from decimal import Decimal, ROUND_HALF_EVEN


def revalue(foreign_amount: str, booked_value: str, closing_rate: str) -> Decimal:
    closing_value = (Decimal(foreign_amount) * Decimal(closing_rate)).quantize(
        Decimal("0.01"), rounding=ROUND_HALF_EVEN
    )
    return closing_value - Decimal(booked_value)


print(revalue("10000.00", "10800.00", "1.0842"))  # 42.00

The rate comes back as a string and goes straight into Decimal. A float anywhere in that path would defeat the point. If you want the full reasoning, read currency conversion rounding without floating-point errors.

If you hold many currencies, the one-base endpoint (GET /v1/rates/USD?quote=EUR,GBP,JPY) returns up to 20 quotes in a single request unit, which cuts the cost of a large snapshot. Check the response shape in the REST documentation before parsing it. Note that its rates are expressed from that base, so keep the direction consistent with your table.

Handling stale, derived and failed captures

A snapshot job should never silently write something questionable.

  • Stale rate. Stale rates are flagged, not withheld. For fiat, "stale" means the observation is older than 5 minutes. The script above stores the row and reports it for review. A reasonable rule is to retry a few times, a minute apart, and only accept a stale rate with a human sign-off.
  • Derived rate. Pairs nobody quotes directly are derived through USD, EUR or BTC. That is normal and usually fine for accounting, but the stored type lets you answer "how was this computed?" later.
  • Unsupported or invalid codes. A typo in a currency code returns invalid_asset_symbol. Validate codes against the free catalog first; see currency code validation.
  • Throttling and outages. On rate_limit_exceeded, wait retry_after_seconds. On temporarily_unavailable, retry with backoff. Match on the error code only; the error reference lists them all.

The job makes only a handful of requests, so quota is a non-issue, even on a free plan. Still, running it twice (once at the cutoff, once as a safety rerun) is cheap insurance, and your unique key keeps the first row.

Close-process checklist

  1. Export currencies with open balances from the ledger.
  2. Run the snapshot at the documented cutoff.
  3. Review any rows flagged as stale or missing.
  4. Compute revaluation entries from the stored rates, not from a fresh call.
  5. Post the entries, and attach the rate rows to the journal reference.
  6. Schedule the reversal for the next period if your policy requires it.

Step 4 matters most. Once a period is closed, every report and re-run must read the stored rates. Calling the API again would give you today's rate, and the numbers would no longer reproduce.

Try it on the free plan

You can build and test this whole job on the free plan, which needs no credit card. Sign up, create a key, and try a pair in the dashboard playground. If your balances span many currencies, compare plans once you know your monthly run count.

All articles →
Currency Revaluation: Snapshot Month-End Exchange Rates — GetRatesAPI