Cannot import StockDataStream

Getting the error “ImportError: cannot import name ‘StockDataStream’ from ‘alpaca.data’” for the following code.

alpaca-py is installed.

from alpaca.data import StockDataStream

from api import *

# keys are required for live data

#crypto_stream = CryptoDataStream("api-key", "secret-key")

# keys required

stock_stream = StockDataStream(ALPACA_API_KEY_ID,ALPACA_API_SECRET_KEY)

print(stock_stream)
1 Like

Hi, did you fix it? I’m getting the same error- alpaca-py is installed

@dana The imports from from the alpaca-py SDK can be challenging. In this specific case try the following

from alpaca.data.live.stock import StockDataStream

A general approach to finding where to import things from is to check out the reference section of the documentation. For example, the StockDataStream class is documented here and shown below.

Notice the full path to the class is provided. This is true of all the classes. Simply include that full path in your import statement. There often can be shortcuts but that will always work.