Price calculation

Pricing

Tick Math

price=1.0001tprice =1.0001^t

Where t is the exchange provided tick value.

Gotchas

Decimals

Alcor Exchange's provided tick returns pricing based on the conversion from token B to token A . By taking a look at TLM|WAX token pair there's a notable issue. The tick-based price actually returns the frontend displayed value multiplied by 10410^4. This is due to the difference of decimals supported by each of the tokens at this token pair.

alien.worlds TLM has 4 decimals. eosio.token WAX has 8 decimals.

It is also publicly known that TLM is tokenA and WAX is tokenB

To handle this apparent issue, the following decimals correction should be applied:

conversionFactor=10(tokenADecimalstokenBDecimals)conversionFactor = 10 ^(tokenADecimals - tokenBDecimals)

trueTokenBPrice=tickPriceconversionFactortrueTokenBPrice = tickPrice * conversionFactor

Pricing precision

We recommend utilizing the target token's amount of decimals as the price precision to maintain a high-level of accuracy.

TokenA pricing

Calculating tokenA pricing by directly converting it from tokenB price is prone to rounding issues. Basis Points (or Bips) is a common technique that helps avoid price precision loss when dealing with small numbers. 1 bip equals 0.01 % and 10000 bips represents 100%.

With this in mind, the following tokenA price calculation is the most adequate:

trueTokenAPrice=(10000/trueTokenBPrice)/10000trueTokenAPrice = (10000 / trueTokenBPrice) / 10000

Last updated