Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
866 views
in Technique[技术] by (71.8m points)

extract - python plug to stock data extraction

I am trying to create a script that extracts the current price information for a list of stocks/ETFs at regular intervals via python programming. Is there a way to do this or related libraries available? The idea is to extract the prices of a list of stocks and store them in a data frame. The data frame would refresh with the new price information at regular intervals, say every 15 mins or 1 hour. Would appreciate it if you could point me in the right direction.

Thank you and Happy new year!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

There are some great libraries that can do a trick for you. For example, yfinance. You can refresh values using your own script.

Here is the basic snippet for demo.

# pip install yfinance
import yfinance as yfin
stockName = 'AMZN'
startDate = datetime.date(1998, 1, 1).strftime('%Y-%m-%d')
endDate = datetime.date(2019, 12, 31).strftime('%Y-%m-%d')
df = yfin.download(stockName, start = startDate, end = endDate, progress=True)
df['Date'] = df.index
df = df.reset_index(drop=True)
df = df.reindex(columns=['Date','Open','High','Low','Close','Adj Close','Volume'])
df

Here is your dataframe that you can use for other purposes. enter image description here


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...