Currently I am downloading the whole json file from here https://api.raydium.io/v2/sdk/liquidity/mainnet.json
and save it into json file, then get the pool info. Code given below for further understanding:
def fetch_pool_keys(mint: str):
amm_info = {}
all_pools = {}
try:
# Using this so it will be faster else no option, we go the slower way.
with open('all_pools.json', 'r') as file:
all_pools = json.load(file)
amm_info = extract_pool_info(all_pools, mint)
except:
resp = requests.get('https://api.raydium.io/v2/sdk/liquidity/mainnet.json', stream=True)
pools = resp.json()
official = pools['official']
unofficial = pools['unOfficial']
all_pools = official + unofficial
# Store all_pools in a JSON file
with open('all_pools.json', 'w') as file:
json.dump(all_pools, file)
try:
amm_info = extract_pool_info(all_pools, mint)
except:
return "failed"
As you can see, I first check it in the downloaded file but if the key which is base mint and quote mint (SOL/USDC/USDT) is not there, then it downloads the file again.
My main concern: At the time of sending request, the code takes longer to download mainnet.json file and as we all know raydium updates the pools every minute or so. Due to which, I am asking for suggestions to speed up the download process or implement an alternative method to downloading mainnet.json