0

I am having some issues doing the next:

I am using coingecko's API to retrive data from market. I want to make a while loop to retrive a df of the market every hour to calculate volume average of all iterations. So my plan is:

1.- Get a df_1 of all coins

df sample:

enter image description here

2.- Wait sometime to take another df_2

3.- Comapre df_2 with df_1 and sum volume of df_1 to df_2 and divide by number of iterations (to calculate average).

4.- Then make df2 to become df1 for the next iteration.

What I did so far is getting first df but I am getting lost in order to compare the second one and prepare the result for the next iteration.from pycoingecko

 import CoinGeckoAPI
 import pandas as pd
 import time
 cg = CoinGeckoAPI()

 coin_list = [code['id'] for code in cg.get_coins_list()]
 df_new = pd.DataFrame()
 while True:
    counter = 0
    def_dict = {}
    while counter < len(coin_list):
        # need to do this because API dont accept request larger than 500 coins.
        temp_dict = cg.get_price(ids=[code for code in coin_list[0+counter:500+counter]],vs_currencies='usd',include_market_cap=True,include_last_updated_at=True,include_24hr_change=True,include_24hr_vol=True)
        def_dict.update(temp_dict)
        counter += 500
        df_temp = (pd.DataFrame.from_dict(def_dict)).T
        # Only need top 3000 coins
        df_temp = df_temp.sort_values(by=['usd_market_cap'],ascending=False)[:3000]
        # create a column to store average price.
        df_temp['average'] = 0
        # create a column to store number of iterations.
        df_temp['iterations'] = 0 
        # Compare this df to the old created ???????
        # Make df_temp`to be df_new to set up next iteration????
    time.sleep(60)

Thanks for any help!

0 Answers0