How can I get the last minute data of the day on yahoo with python code
Hi,
You can use the yfinance module to fetch the last-minute data of the day.
You first need to install the finance module by running the following line of code from your Jupyter Notebook:
!pip install yfinance
We will use the download method with the parameters: ticker, period, interval
- ticker: The name of the tickers you want the stock market data for. If you want stock market data for multiple tickers then separate them by space.
- period: The number of days/month of stock market data required. The valid frequencies are 1d, 5d, 1mo, 3mo, 6mo, 1y, 2y, 5y, 10y, ytd, max
- interval: The frequency of the stock market data. The valid intervals are 1m, 2m, 5m, 15m, 30m, 60m, 90m, 1h, 1d, 5d, 1wk, 1mo, 3mo
The below code fetches the stock market data for Apple Stock for the past 5 days of 1-minute frequency:
import yfinance as yf
data = yf.download(tickers=“AAPL”, period=“5d”, interval=“1m”, auto_adjust=True)
data.head()
Please note that to get real-time data you might need to upgrade to the premium version of yfinance since the free version might have a delay of about 15 minutes, that is, if you request the current data, you will receive data that is 15 minutes old.
Thanks.
I want to get the data one minute or two minutes before the last close of the day at the end of the day Thanks.
Hi there,
As mentioned in the previous comment, you can use the interval attribute of the download method.
Here is an example of how to get the data one or two minutes before the last closing time of the day:
import yfinance as yf
ticker = "RELIANCE.NS"
data = yf.download(ticker, end = '2023-05-18', interval ='1m')
# Print the data
data.tail()
This will show you the stock price data few minutes before the closing time on 17th May, 2023. Similarly to get the data for 18th May, you can enter the end date as '2023-05-19'.
Hope this helps.
Thanks.
Thanks.