'Looping through list and making api call, index only returns 0

I am using the CCXT library in Python 3.10

I am trying to call multiple tickers and multiple rows of ohlcv data for each ticker in a single loop. The function returns all tickers and ohlcv data that I want, but each index is returning 0. I've tried using range/len but since the index only returns 0 for each row, that doesn't work.

Here is my code:

exchange = ccxt.phemex({
    'apiKey': config.apikey,
    'secret': config.secret})

symbols = ['AAVE/USD:USD', 'BTC/USD:USD', 'ETH/USD:USD', 'GOLD/USD:USD', 'LINK/USD:USD', 'LUNA/USD:USD'] 

def ema(df):
ema = df['close'].ewm(com=20).mean()
return ema

def bars():
    for i in symbols:
        tickers = exchange.fetch_ohlcvc(i, timeframe='1m', limit=50)
        for j in tickers:
            df = pd.DataFrame({'symbol': [i],
                               'timestamp': j[0],
                               'open': j[1],
                               'high': j[2],
                               'low': j[3],
                               'close': j[4],
                               'volume': j[5],
                               'c': j[6]})

            #Change timestamp to datetime
            df['timestamp'] = pd.to_datetime(df['timestamp'], unit='ms')
            df = df.assign(ema = ema(df))
            
            print(df)

# Here is an output of the first couple bars, as you can see, the index only returns 
# 0 for each new row. I would like it to return the true index in order or the 
# index 0-end for each ticker symbol.

Fetching new bars for 2022-03-10T11:35:05.007889
     symbol           timestamp   open   high    low  close  volume  c  \
0  AAVE/USD:USD 2022-03-10 18:14:00  118.8  118.8  118.8  118.8   208.0  1   

 ema  
0  118.8  
     symbol           timestamp    open    high     low   close  volume  \
0  AAVE/USD:USD 2022-03-10 18:15:00  118.54  118.54  118.54  118.54   444.0   
     ema  
0  118.8 


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source