How do I get all stocks' name from the market into a Python list?

Hi guys,

Has anyone tried to pull all the stock names from the market using Alpaca api? could you tell me the function name?

Thank you.


first, you need to create an instance of the REST API alpaca provides. After this, there is a method to get all available stocks (assets) from the market.

import alpaca_trade_api as alpaca

api = alpaca.REST('<YOUR_API_KEY_ID>', '<YOUR_API_SECRET_KEY>', '<URL>')

active_assets = api.list_assets(status='active')  # you could leave out the status to also get the inactive ones

This will return a list of Assets. These Assets have attributes (a list of them can be found here) To print out the more relevant information you could use the following lines of code:

for asset in active_assets:
    print(f"{asset.symbol}  \t{}")