¿Los cálculos internos se realizan en coma flotante o con un número fijo de decimales? ¿Los valores siempre se redondean?

Calculated versus displayed precision

El redondeo se realiza generalmente al número entero más cercano al realizar cálculos y se reduce cuando se muestra.

Las opciones "Obtener información de activos" y "Obtener pares de activos negociables" proporcionan información sobre cuántos decimales usan los distintos activos internamente y cuántos se muestran.

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:

"L2A7BN-OLRUR-DGZH7F":{"refid":"T5JORM-HM432-GQ3RGY","time":1639991413.4671,"type":"trade","subtype":"","aclass":"currency","asset":"ZUSD","amount":"-1.4541","fee":"0.0000","balance":"124.7277"}

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.

Calculated versus displayed precision

¿Necesita más ayuda?