# Price format differnce in API data

Hi, I do work with the data from the api, it works pretty nice and is useful to me. But one thing I noticed is that the prices do not have a logical behavior. Look for example at those two pairs against BTC.

One pair is (compared to the wavesdex) divided by 8 zeros and the other pair is even divided by 12 zeros to get the same price on the DEX. But how I can get this information from this pages. Because now its hard to program something which I can use uniformly.

https://matcher.wavesplatform.com/matcher/orderbook/8HYDtqEuHj3RDcwR8yxEvPq1qQSB9FazC8wMHtRb2TFe/8LQW8f7P5d5PZM7GtZEBgaqRPGSzS3DfPuiXrURJ4AJS
price
11100
Wavesdex price: 0.00000111

https://matcher.wavesplatform.com/matcher/orderbook/EYz8Zvs62D4d7F5ZgXHCWuzuFaZg63FYnfVQrTWQoLSK/8LQW8f7P5d5PZM7GtZEBgaqRPGSzS3DfPuiXrURJ4AJS
price
101000000
Wavesdex price: 0.000101

In the process of issuing a token, the issuer chooses the number of decimal places. When you receive a response for an API request, you need to divide the received value by 100,000,000, if the decimal places were 8; 10,000,000, if the decimal places were 7 and so on.

The amount of digits belong on a mathemetical combination from the 2 pairs there digits substracted with eachother and multiplied, I have to look up the formule for this, will come back later today/this week with the formule

I was speaking about balances to explain the difference between number of digits. To calculate trades u have to use a bit different formulas.

But how I can know this information just from the API?

There are really big differences and I can not adjust this data by hand of courseâ€¦

You can check how itâ€™s done in WavesCS lib. Price scale is calculated based on number of digits in both price and amount assets.

``````public static long PriceToLong(Asset amountAsset, Asset priceAsset, decimal price)
{
var decimals =  8 - amountAsset.Decimals + priceAsset.Decimals;
var scale = new decimal(1, 0, 0, false, (byte) decimals);
return decimal.ToInt64(price / scale);
}

public static decimal LongToPrice(Asset amountAsset, Asset priceAsset, long price)
{
var decimals =  8 - amountAsset.Decimals + priceAsset.Decimals;
var scale = new decimal(1, 0, 0, false, (byte) decimals);
return price * scale;
}
``````

In fact the returned price is price of one assetâ€™s satoshi against second assetâ€™s satoshi multiplied by 10^8

1 Like

Iâ€™m not sure I really understand it though. For coding I used Python and not this library. Sorry I am just a beginner with coding, I do only understand the very basis.

At this moment I think my code is able to take the correct format from:
amountAsset/priceAsset

But for now I do not have solved the code to make those decimals in the correct way to compare correctly the pair.

Do you use PyWaves library? Maybe this can be useful for your code (this is a part of trading bot example from here https://github.com/wavesplatform/demo-python-trading-bot/blob/master/SimpleBot.py):
Here we define trading params for WAVES-BTC pair

``````order_fee = int(0.003 * 10 ** pywaves.WAVES.decimals) # 0.003 WAVES (pywaves.WAVES.decimals = 8)

amount_asset = pywaves.WAVES
price_asset_id = "8LQW8f7P5d5PZM7GtZEBgaqRPGSzS3DfPuiXrURJ4AJS" # BTC
price_asset = pywaves.Asset(price_asset_id)

waves_balance = my_address.balance() #balance of amount asset
btc_balance = my_address.balance(bot.price_asset_id) #balance of price asset

waves_btc = pywaves.AssetPair(amount_asset, price_asset)
order_book = waves_btc.orderbook()
best_bid = order_book["bids"][0]["price"]

bid_amount = int((btc_balance / best_bid * 10 ** pywaves.WAVES.decimals) - order_fee #translate into amount asset

``````

if it is not helpful, please send your problematic piece of code and we try to solve it here

Thank you, actually this code is working. Before I used it incorrectly I think. One thing though. If instead using the Decimals for WAVES using it for another currency I think is showing wrong decimal numbers.

For example:
2SWaPDm46HbKwrhoq8qmwE5ahiPXjgPS3aoW6mRU8xpb

But I do think it is with other coins as well.

This is a bit of thread necro but can anyone confirm if these price calculations are working with the latest pywaves? The internal code for calculating the price submitted to the matcher changed in August.

PR with the change: https://github.com/PyWaves/PyWaves/pull/55
Issue discussing the change: https://github.com/PyWaves/PyWaves/issues/54