API not working to fetch price, it returns null for usdPrice

It is giving null as price. Please check!

Yes, we’ll have to investigate the problem.

1 Like

Please do. Many users start complaining. Hope you understand.

meanwhile you can try with to_block parameter with latest block

what change should I make in the api? what integer should be put in “to_block” parameter?

I am using Python in the backend.

Ok, didn’t know that you want python:

import requests

def get_block(date_="2031-10-10"):
    url = 'https://deep-index.moralis.io/api/v2/dateToBlock?chain=bsc&date=%s' % date_

    headers = {
        "Content-Type": "application/json",
        "X-API-Key": "API_KEY"
    }
    statusResponse = requests.request("GET", url, headers=headers)
    data = statusResponse.json()
    return data['block']
    

def get_price(address):
    latest_block = get_block()
    url = 'https://deep-index.moralis.io/api/v2/erc20/%s/price?chain=bsc&to_block=%s' % (address, latest_block)

    headers = {
        "Content-Type": "application/json",
        "X-API-Key": "API_KEY"
    }
    statusResponse = requests.request("GET", url, headers=headers)
    data = statusResponse.json()
    print("price =", data['usdPrice'])

get_price("ADDRESS")

1 Like