For information on changes for our US clients, please visit our Support Center article.

A causa dell’incremento della domanda, la verifica dell’account potrebbe subire ritardi. Evita di inviare più richieste e, per ottenere risultati migliori, rivedi in anticipo i requisiti del documento.
Decimal precision for API calculations

Calculated versus displayed precision

Internal API calculations are performed using as many decimal places as necessary depending upon the precision of the currency in question, but displayed values are sometimes rounded/truncated to achieve a usable value or for formatting purposes.
For example, Bitcoin (BTC) calculations use up to 10 decimal places (the maximum usable precision for BTC is 8 places), but are sometimes displayed using only 5 decimal places. Similarly, US Dollar (USD) calculations use up to 4 decimal places (the maximum usable precision for USD is of course 2 places), but are often displayed using only 2 decimal places.
The REST API Assets endpoint can be used to determine the maximum decimal precisions for individual currencies:
$ ./krakenapi Assets asset=xbt,usd

As shown, the Assets endpoint provides the calculation decimal precisions via the decimals fields, and provides the display decimal precisions via the display_decimals fields.

Matching local values with API values
Values derived from local calculations (such as calculating balance changes from a trade's price and volume) often have more decimal places than required, and need to be rounded/truncated to match the values provided by the API.
For example, a SHIB/USD order to buy 50,123 SHIB at $0.00002901 results in a trade worth $1.45406823 (50,123 x 0.00002901 = 1.45406823), but the REST API Ledgers endpoint shows that the USD balance decreased by a smaller precision value of $1.4541:
The solution to this type of decimal precision discrepancy is to round/truncate local values to match the decimal precision provided by the REST API Assets endpoint.
Continuing the SHIB/USD example, the Assets endpoint indicates a USD calculation precision of 4 (see the previous section above), hence the locally calculated value of $1.45406823 should also be rounded/truncated to a decimal precision of 4:
  • 50,123 x 0.00002901 = 1.45406823 rounded to 4 places = 1.4541
As shown, by rounding/truncating to the appropriate decimal precision, the final value of $1.4541 corresponds exactly to the value provided by the Ledgers endpoint, allowing local values to be matched with API values successfully.