Multi-Currency Dashboard: How to Show a Total Balance in One Currency

6 min read

Multi-Currency Dashboard: How to Show a Total Balance in One Currency

A multi-currency dashboard has one job that looks trivial: take balances held in several currencies and show a single total in one reporting currency. Convert each balance with a current exchange rate, add the results, round once at the end. The details are where dashboards go wrong: floats, rates fetched at different moments, stale data shown as fresh, and rows that don't add up to the total.

This article walks through the approach step by step, with a working Python example. The principles apply to any language: pick one reporting currency, convert every balance with exact decimals, keep track of how old the rates are, and round only when you display.

Start with a reporting currency and a clear contract

Before writing code, decide what the total means. A dashboard that holds 1,200.00 EUR, 80,000 JPY and 0.05 BTC has no natural total. It only has one once you choose a reporting currency, such as USD, and state that every figure is converted at a recent market rate.

A few decisions make the rest easy:

  • One reporting currency per view. Let users switch it, but compute each view from scratch in a single currency. Don't convert a total from one reporting currency into another; that stacks two roundings.
  • Keep native balances untouched. Store and display the original amount in its own currency (1,200.00 EUR) next to the converted figure. The converted value is a derived view and never the source of truth.
  • Label the total. "Total in USD, rates as of 10:02 UTC" is honest. A bare number looks like a fact when it is really an estimate that moves every minute.

If your users also hold gold or crypto, the same model works. XAU, XAG and crypto codes convert like any other asset. See the full list of supported currencies.

Convert each balance, then add

The order of operations matters. Convert every balance into the reporting currency, keep full precision, and sum the converted values. Round once, at the end, for display.

Two rules prevent most bugs:

  1. Never use binary floats for money. 0.1 + 0.2 is not 0.3 in floating point, and errors accumulate across many rows. GetRatesAPI returns rates and amounts as JSON strings precisely so you can parse them into a decimal type. Our guide to currency conversion rounding without floating-point errors covers the details.
  2. Don't round each row and then sum the rounded rows. That introduces a small drift that depends on how many rows you have. Sum the unrounded values and round the total.

The API doesn't round results for you. The caller decides precision, which is what you want here, because the right precision depends on the currency: 2 decimals for USD or EUR, 0 for JPY, 8 for BTC.

A working example in Python

This example fetches a rate for each held currency into the reporting currency, multiplies with Decimal, and tracks the oldest as_of and any stale rates. It uses the current rate endpoint and reads the key from an environment variable.

import os
from decimal import Decimal, ROUND_HALF_EVEN

import requests

API = "https://api.getratesapi.com"
HEADERS = {"Authorization": f"ApiKey {os.environ['GETRATES_API_KEY']}"}


def get_rate(base: str, quote: str) -> dict:
    resp = requests.get(
        f"{API}/v1/rates/{base}/{quote}", headers=HEADERS, timeout=10
    )
    if not resp.ok:
        # Match on the "code" field only, never on the message text.
        raise RuntimeError(resp.json()["code"])
    return resp.json()


def total_in(reporting: str, balances: dict[str, str]):
    total = Decimal("0")
    oldest_as_of = None
    stale = []

    for currency, amount in balances.items():
        value = Decimal(amount)
        if currency == reporting:
            total += value
            continue

        data = get_rate(currency, reporting)
        total += value * Decimal(data["rate"])

        # ISO 8601 UTC timestamps in the same format sort correctly as strings.
        if oldest_as_of is None or data["as_of"] < oldest_as_of:
            oldest_as_of = data["as_of"]
        if data["status"] == "stale":
            stale.append(currency)

    return total, oldest_as_of, stale


balances = {"EUR": "1200.00", "JPY": "80000", "USD": "350.25"}
total, as_of, stale = total_in("USD", balances)

print(total.quantize(Decimal("0.01"), rounding=ROUND_HALF_EVEN), "USD")
print("oldest rate:", as_of, "| stale:", stale)

The Decimal(data["rate"]) call works directly because the rate arrives as a string such as "1.0842". No float ever touches the value.

Make freshness visible in the UI

Every GetRatesAPI rate carries two fields that a dashboard should use: as_of and status.

  • as_of is the time of the observation. The oldest as_of across all your rows is the honest timestamp for the whole total.
  • status is "fresh" or "stale". Crypto is stale after 1 minute and fiat after 5 minutes. Stale rates are flagged, not withheld, so the decision about what to show is yours.

Here is a simple policy that works for most dashboards:

SituationWhat to show
All rates freshThe total, with "as of" time
Some rates staleThe total plus a subtle warning naming the affected currencies
A rate could not be fetchedThe native balance, and a total marked "partial"

Also note the type field. A rate is "direct" or "derived". If no market quotes a pair directly, the API derives it through USD, EUR or BTC, and a derived rate's as_of is its oldest input. You don't have to treat the two differently in code, but the as_of you display should come from the response, not from your own clock. For more on this, read cross rates explained.

Keep request counts under control

The naive loop above makes one request per held currency on every page load. With 10 currencies and a few hundred users, that adds up quickly. Three habits keep usage sensible:

  • Deduplicate pairs. Collect the distinct currencies across the whole page first. If three accounts hold EUR, fetch EUR to USD once.
  • Cache briefly. Fiat rates refresh every 60 seconds and crypto every 10 seconds, so caching a rate for less than that interval gives you nothing but wasted calls to avoid. A short TTL matched to the asset type is the sweet spot. How to cache exchange rates without showing stale prices goes through the pattern.
  • Use batch requests where they fit. One call can return up to 20 quotes against a single base for 1 request unit. If your dashboard shows a rate table from one base currency, that's far cheaper than 20 single calls. Our post on getting multiple exchange rates in one API call shows how. Keep in mind that a batch gives you rates from the base to each quote; to value a balance in the reporting currency, you need the rate in that direction, so batch with the reporting currency as the base only when you're prepared to divide by the rate. Division needs an explicit precision and rounding mode, so plan for that.

If you hit a per-second limit during a refresh, back off using retry_after_seconds, as covered in the rate limit handling guide.

Avoid the classic dashboard mistakes

Rows that don't add up. If each row shows a rounded value and the total is rounded separately, the visible rows may differ from the total by a cent. That's normal for estimates. Add a note such as "totals are calculated from unrounded values," or show fewer decimals on the rows. Don't quietly adjust one row to force a match.

Mixed snapshots. Fetching USD to EUR now and JPY to USD thirty seconds later and calling it one total is fine for an estimate, but be aware of it. Show the oldest as_of and the user sees exactly how far apart the inputs could be.

Treating the total as a ledger value. A dashboard figure is an estimate for display. If a figure feeds an invoice or an accounting entry, store the rate and its as_of alongside the amount at the moment you use it. The foreign currency invoicing guide explains what to record.

Unsupported or mistyped codes. An unknown code returns invalid_asset_symbol or unsupported_pair. Validate the user's held currencies against the free catalog endpoint (/v1/assets), which is not billed, and handle errors by code, as described in the error handling guide.

Build your dashboard total

You need an API key, one reporting currency and a decimal type. The free plan includes 500 request units a month with no credit card, which is enough to prototype the code above. Sign up here, try the endpoints in the dashboard playground, and check pricing when your page views grow. The REST documentation covers authentication, responses and errors in detail.

All articles →
Multi-Currency Dashboard: Total Balance in One Currency — GetRatesAPI