Exchange Rate Markup: How to Add a Margin to Live Rates Correctly

5 min read

Exchange Rate Markup: How to Add a Margin to Live Rates Correctly

If you convert money for customers, you will probably want an exchange rate markup: a small margin on top of the market rate that covers your costs, risk or fees. The correct way is to fetch a live reference rate, apply the margin in the direction that works against the customer, round once at the end, and store both the reference rate and the rate you actually charged.

Most mistakes here are small but expensive: applying the markup in the wrong direction, rounding the rate before multiplying, or being unable to explain a price to a customer three months later. This article walks through the math, the common pricing models and a working example.

What an exchange rate markup is

A markup (also called a margin or spread) is the difference between the reference rate you get from a data source and the rate you offer your customer. If the reference rate for USD to EUR is 0.9223 and you give customers 0.9131, your markup is roughly 1%.

GetRatesAPI returns one rate per pair, with no separate buy and sell quotes. Treat that number as your reference rate and apply your own margin on top. The API does not know your fees, so the margin is always your business decision. This is data, not advice on what to charge.

Two terms you will see:

  • Percent markup: a fraction of the rate, such as 1.5%.
  • Basis points (bps): one hundredth of a percent. 100 bps is 1%, 150 bps is 1.5%. Storing the margin as an integer number of bps avoids decimal-fraction confusion in config files and databases.

Which direction does the margin go?

The margin must always leave the customer slightly worse off than the reference rate. Which way you adjust depends on what the customer fixed.

The customer fixes the amount they send. They convert 100 USD to EUR. Reduce the rate:

customer_rate = reference_rate × (1 − margin)
received      = amount × customer_rate

With a reference rate of 0.9223 (an example, not a live quote) and 1% margin: 0.9223 × 0.99 = 0.913077. The customer receives 100 × 0.913077 = 91.3077, which rounds to 91.31 EUR. Without a margin it would have been 92.23 EUR.

The customer fixes the amount they receive. A product costs 100 EUR and the customer pays in USD. Increase what they pay:

customer_rate = reference_rate × (1 + margin)
to_pay        = amount × customer_rate

With an example EUR to USD rate of 1.0842 and a 2% margin: 1.0842 × 1.02 = 1.105884, so 100 EUR costs 110.5884, rounded up or to nearest to 110.59 USD.

A common bug is using rate × (1 + margin) for both cases. In the first case that pays the customer more than the market, and you lose money on every transaction.

Common pricing models

ModelHow it worksGood forWatch out for
Percent markupRate multiplied by (1 − m) or (1 + m)Simple, scales with amountSmall amounts yield tiny fees
Flat feeFixed fee per conversion, rate untouchedTransparent pricingLarge amounts look cheap, tiny ones look expensive
Percent plus minimumPercent markup, with a minimum feePayouts and transfersNeeds a clear fee line on screen
TieredMargin shrinks as the amount growsBusiness customersMore rules to test and document

Whichever you choose, show the customer the rate they actually get. A rate shown without the margin and a result that does not match it is the quickest route to support tickets.

Apply a markup in code with exact decimals

Do the math with decimals, never floats. The API sends rates as JSON strings so you can parse them straight into a decimal type. Here is a Python example that fetches a rate and applies a margin in basis points:

import os
import requests
from decimal import Decimal, ROUND_HALF_UP

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


def quote_with_margin(base, quote, amount, margin_bps, minor_units=2):
    resp = requests.get(f"{API}/rates/{base}/{quote}", headers=HEADERS, timeout=5)
    resp.raise_for_status()
    data = resp.json()

    reference = Decimal(data["rate"])
    factor = Decimal(10000 - margin_bps) / Decimal(10000)
    customer_rate = reference * factor

    exact = Decimal(amount) * customer_rate
    step = Decimal(1).scaleb(-minor_units)  # 0.01 for two decimals
    received = exact.quantize(step, rounding=ROUND_HALF_UP)

    return {
        "reference_rate": data["rate"],
        "margin_bps": margin_bps,
        "customer_rate": str(customer_rate),
        "amount": amount,
        "received": str(received),
        "as_of": data["as_of"],
        "status": data["status"],
    }


print(quote_with_margin("USD", "EUR", "100.00", 100))

Three details matter:

  1. Do not round the rate. Keep customer_rate at full precision and round only the final money amount. Rounding 0.913077 to 0.9131 first changes the result for large amounts.
  2. Round once, at the end. Use the minor-unit count of the target currency: JPY has none, EUR and USD have two, and some currencies have three. See our guide to currency conversion rounding for the full rules.
  3. Use your own rounding mode deliberately. Half-up is common, but pick one and document it.

If you prefer one call instead of two steps, GET /v1/convert?from=USD&to=EUR&amount=100.00 returns an exact converted_amount without rounding. You can then multiply by (1 − margin) yourself. Either way, the current rate endpoint gives you the as_of timestamp to store.

Handle stale rates and rate movement

Every rate carries as_of and status. For a customer-facing quote, decide in advance what your service does when status is "stale". Reasonable options:

  • Refuse to quote and show a friendly retry message.
  • Quote with a wider margin to cover the extra uncertainty.
  • Allow the quote only for low-value transactions.

Stale rates are flagged, not withheld, so the decision is yours and you must check the field.

Also think about how long a quoted price is valid. Rates move every minute or less, so a margin that was comfortable at 10:00 may not cover the market at 10:20. Quoting with an expiry, as described in how to lock an exchange rate at checkout, protects both sides. If you cache reference rates to save requests, keep the cache short and respect as_of; our post on caching exchange rates without showing stale prices covers the pattern.

What to store with every converted amount

When a customer asks why they got 91.31 EUR for 100 USD, you need to answer from data, not from memory. Store per transaction:

  • The base and quote currency codes.
  • The reference rate as a string or decimal column (not a float).
  • The margin in bps, and the resulting customer rate.
  • The as_of timestamp and status returned by the API.
  • The original amount, the unrounded result, and the rounded amount you charged or paid out.
  • Whether the rate was direct or derived. A derived rate's as_of is its oldest input, which is useful in audits.

Margins change over time, so save the margin used per transaction rather than looking it up later from a config file.

Add a margin to live rates with GetRatesAPI

GetRatesAPI gives you the reference side: live rates for about 170 world currencies, metals and thousands of crypto assets, with any pair available, exact decimal strings and a freshness flag on every response. You add the margin, the rounding and the business rules.

To try it, create a free account, copy an API key and run the example above, or test the endpoints in the dashboard playground. Check the pricing page when you are ready to size a plan for your conversion volume.

All articles →
Exchange Rate Markup: Add a Margin to Live Rates — GetRatesAPI