# Exchange rates

Back to the [README](../README.md).

A 4.15 rate with `buyCurrency` X, `sellCurrency` Y and `exRate` R means
**one X costs R Y**. The spec doesn't say which way round a rate applies;
`YspSimulator.ExchangeRates` is the one place that decides it. Rates are
one-way: setting `USD`/`AED` doesn't set `AED`/`USD`.

Fund Transfer's `amount` is in the destination currency, so it buys the
destination currency with the source's: the source pays `amount` × the
`USD`/`AED` rate for an AED → USD transfer. A sent `exchangeRate` is used
instead of the saved rate, as the spec says. For example, with
`USD`/`AED` = `3.6725`, sending 10 USD costs the source 37 AED (36.725
rounded).

Debit/Credit's `amount` is in the request's `currency`, so it buys the
account's currency: with `AED`/`USD` = `0.2723`, a 100 USD debit takes
367 AED (367.24 rounded) from an AED account. There's no `exchangeRate`
field, so only saved rates are used.

Balances are whole units, so converted amounts round half up.
