Get last 100 bars for hundreds of stocks or historical data for hundreds of stocks?

How do get the last 100 bars for hundreds of stocks?

Rationale:

  1. Get all active tickers in Alpaca
  2. Get last 100 bars for all stocks
  3. Calculate SMA9 and SMA50 locally
  4. Filter stocks where SMA9>SMA50
  5. ???
  6. Profit
  7. Repeat Steps 1-4 every hour

def getAlpacaTickers():
list_of_objects = api.list_assets(status=‘active’)
data = pd.DataFrame.from_records([s._raw for s in list_of_objects])
tickers = data.symbol
return tickers

def getLatestPrices(symbols, aggr, bars=5,slp=5):
    end = getTime()
    
    def get_barset(symbols):
        return api.get_barset(symbols, aggr, limit = bars, end=end)

    # The maximum number of symbols we can request at once is 200.
    barset = None
    idx = 0
    while idx <= len(symbols) - 1:
        if barset is None:
            barset = get_barset(symbols[idx:idx+200])
        else:
            barset.update(get_barset(symbols[idx:idx+200]))
        idx += 200
        sleep(slp)
    return barset.df.sort_index(ascending=False)

I researched online and found some code to get last 100 bars of tickers but I can only process 200 at a time, and I’m restricted by the numbers of requests per minute. Can you provide some guidance on how to get last 100 bars for thousands of stocks, or SMA9 and SMA50 for thousands of stocks?

Thank you!!!