I have a tacky problem. On my website, you can find current price tracker for crypto coins as a purely content filler element. I get my data from coin API, you are allowed 100 request's per day.
def crypto_api_prices(request):
api_base_url = 'https://rest.api.io/v1/exchangerate/'
api_key = '==============='
headers = {
'X-CoinAPI-Key': api_key,
}
crypto_tickers = ["BTC","ETH","ETC","RVN"]
crypto_api_links = [api_base_url+x+"/"+"USD" for x in crypto_tickers ]
crypto_api_prices = [requests.get(x, headers=headers).json()['rate'] for x in crypto_api_links]
context = {
"cryptoPrices":crypto_api_prices
}
return context
I'm calling this function in my home view. Unfortunately, if I have couple of visitors daily this generates 100 requests pretty fast and my element isn't working anymore.
What I want to achieve is set crypto_api_prices as a global variable and update it every hour, so no matter how many users will be on my page I will generate only 24 requests.
Is this a good idea? Are there alternatives? Of course I can buy more requests but this website is a "passion" project so I want to keep costs down
