Calculate token price

it seems that i need to do some extra math after i get the token price using the deep index api. this is my code.

token_price = 'https://deep-index.moralis.io/api/v2/erc20/0x95aD61b0a150d79219dCF64E1E6Cc01f0B64C4cE/price?chain=eth&to_block=’+str(block_number)

headers = {‘X-API-Key’: moralis_api_key}

response = requests.request(“GET”, token_price, headers=headers)

resp = response.json()

i’m trying to get the current price for SHIB. the usd price i get from the api is $1.1654369614863e-05

the price on coinmarketcap is $0.00001171

You don’t have to put in the block number to get the current price, which is currently showing a usdPrice of 0.000011730365938103. Can you try it again?

it’s weird, because when i go to the moralis site and try it, i get the correct usd price.

{
“nativePrice”: {
“value”: “7548892884”,
“decimals”: 18,
“name”: “Ether”,
“symbol”: “ETH”
},
“usdPrice”: 0.000011464806100532,
“exchangeAddress”: “0x1f98431c8ad98523631ae4a59f267346ea31f984”,
“exchangeName”: “Uniswap v3”
}



but when i run my python code i get a different response:

{'nativePrice': {'value': '7548892884', 'decimals': 18, 'name': 'Ether', 'symbol': 'ETH'}, 'usdPrice': 1.1464806100532e-05, 'exchangeAddress': '0x1f98431c8ad98523631ae4a59f267346ea31f984', 'exchangeName': 'Uniswap v3'}

Can you post your Python code? It looks like Python or the HTTP library you’re using is actually returning the number in a slightly different way.

You can format it:

print(format(response["usdPrice"], '.18f'))
# 1.1464806100532e-05 becomes 0.000011464806100532