Usually, people start listening to the real-time stock price at market open and then save the data at market close. It is suggested to run the code during market hours. The following code gets the real-time stock price every second and then save it for later use. The package yahoo_fin has done exactly that so you can just call its functions if you don’t want to write one yourself.
It is also possible to scrape Yahoo Finance Live stock quotes using web scraping tools.
#!pip install yfinance #!pip install mplfinance from datetime import datetime import yfinance as yf import mplfinance as mpf start_date = datetime(2019, 1, 1) end_date = datetime(2019, 12, 31) data = yf.download('AAPL', start=start_date, end=end_date) mpf.plot(data,type='candle',mav=(3,6,9),volume=True,show_nontrading=True)Īggregated five-minute from one-minute bar | Data from Yahoo Finance Note that you can save the data for later use, but due to backward price adjustment, the Adj Close is likely to change in the future. The full code can be found here on Github.ĭaily price is what you see on the Historial Data tab. I have to spend half of this post on Yahoo Finance so I’ll break it into four sub-sections.
Here is one tip about Yahoo Finance, which is that everything you see on their website can be potentially downloaded or real-time streamed and more likely than not someone has already done so. Google Finance tried similar services but was not as popular. It was temporarily unavailable in 2017 however some fix libraries were posted since then, one of them later became yfinance. You can’t get around Yahoo Finance, one of the first practitioners of financial data democratization and equal-opportunity financial inclusion.