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

Categories

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!


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

1 Answer

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...