I made this Python script to get the price and I got no error for 20 runs:
import requests
import json
import time
smartContractDict = {
0:{"address": "0x0e09fabb73bd3ade0a17ecc321fd13a19e81ce82",
"chain":"bsc", "chain_name":"mainnet", "name":"PancakeSwap", "isVerify": 0, "IsBuy":0, "isSell":0, "PriceVerify":0.00, "PriceBuy":0.00, "PriceSell":0.00},
1:{"address": "0x2170ed0880ac9a755fd29b2688956bd959f933f8",
"chain":"bsc", "chain_name":"mainnet", "name":"ETH-Binance", "isVerify": 0, "IsBuy":0, "isSell":0, "PriceVerify":0.00, "PriceBuy":0.00, "PriceSell":0.00},
}
def get_price(address, chain, chain_name):
provider = 'https://deep-index.moralis.io/api/v2/erc20/%s/price?chain=bsc' % address
headers = {
"Content-Type": "application/json",
"X-API-Key": "<YOUR_API_KEY_HERE>"
}
statusResponse = requests.request("GET", provider, headers=headers)
data = statusResponse.json()
print(json.dumps(data, indent=4))
print("price =", data['usdPrice'])
for j in range(20):
print(j)
for i in smartContractDict:
address = smartContractDict[i]['address']
chain = smartContractDict[i]['chain']
chain_name = smartContractDict[i]['chain_name']
print(i, address, chain, chain_name)
get_price(address, chain, chain_name)
time.sleep(1)
example of output:
0 0x0e09fabb73bd3ade0a17ecc321fd13a19e81ce82 bsc mainnet
{
"nativePrice": {
"value": "51763895777838418",
"decimals": 18,
"name": "Binance Coin",
"symbol": "BNB"
},
"usdPrice": 23.367386736650246,
"exchangeAddress": "0xcA143Ce32Fe78f1f7019d7d551a6402fC5350c73",
"exchangeName": "PancakeSwap v2"
}
price = 23.367386736650246