Currencies and precision
Learn which currency each amount in a response uses and how to calculate with amounts without losing precision.
A response can contain amounts in several currencies. Market prices keep the currency of their market, and converted amounts share one currency per response. Always store an amount together with its currency.
Which currency an amount uses
| Amount | Currency |
|---|---|
market_price_amount | The market's own currency, market_currency_code. This amount is never converted. |
buy_amount, sale_amount, payout_amount | The response currency. |
CSCP valuation | The response currency. |
The response currency is the currency you request. Without it, the API uses your account's base currency, and USD if you have not set one. Changing the base currency in the dashboard changes the default currency of the converted amounts. It does not change market prices.
Use list currencies to inspect the official currency catalogue and its rate fields.
Calculate with decimals
Money and rates are decimal strings. Use a decimal library for calculations and round only at a defined boundary. Do not parse money into binary floating-point numbers and assume exact results.
Why your conversion can differ
Fee processing and the CSCP valuation are computed in CNY internally. The API converts them into the response currency with the official reference rates. A converted amount can therefore differ from your own conversion made at another rate or time.
When you convert a quote yourself:
- Keep the original amount and currency.
- Record the rate you used.
- Label the result as your conversion.
Exchange rates and market fees can change independently.
For the meaning of the converted amounts, read cost calculation.