I have a forever loop that rebalance my portfolio. I call an exchange API which basically does not cost anything as long as I stay within their rate limit (1-2 call per sec), so I loop them forever with minimal sleep time (10 sec).
Then I want to add an API call from Coinmarketcap as a small loop that run once every 10 mins. This is done to avoid their 'free' API limit (333 call/day, and I use 2 calls per loop).
so My forever loop is simply:
while True:
try:
countCMC = 0
for loop
if countCMC == 0 or countCMC % 60 == 0:
get Coinmarketcap api......
countCMC = countCMC + 1
run bunches of rebalance algo......
time.sleep(10)
except:
....
I want to call Coinmarketcap and parse their data to variables, and then use them in my rebalance algo. May be a small loop inside "try" with sleep time?
Update: I have tried to add count and then use modulo, so it runs at the beginning and every 60x10 = 600 sec thereafter. Wonder if there is a better way?