Yahoo Finance API: Difference between revisions
Jump to navigation
Jump to search
(→Usage) |
|||
Line 16: | Line 16: | ||
=Usage= | =Usage= | ||
<font color=darkkhaki>Refactor to get the current price during market hours and get the closing price after market.</font> | |||
<syntaxhighlight lang='py'> | <syntaxhighlight lang='py'> | ||
import yfinance as yf | import yfinance as yf | ||
from datetime import date | |||
m = yf.Ticker('FCOM').info | m = yf.Ticker('FCOM').info | ||
# | print("Symbol", m['symbol']) | ||
data = yf.download('FCOM', ' | |||
# how to get the current price during market hours? | |||
# get the close price after market close | |||
today = str(date.today()) | |||
data = yf.download('FCOM', today) | |||
closing_price = data['Close'].iloc[-1] | |||
</syntaxhighlight> | </syntaxhighlight> | ||
Revision as of 07:22, 14 October 2023
External
- https://github.com/ranaroussi/yfinance
- https://pypi.org/project/yfinance/
- https://towardsdatascience.com/python-how-to-get-live-market-data-less-than-0-1-second-lag-c85ee280ed93
- https://www.makeuseof.com/stock-price-data-using-python/
Internal
Overview
Installation
pip3 install yfinance
Usage
Refactor to get the current price during market hours and get the closing price after market.
import yfinance as yf
from datetime import date
m = yf.Ticker('FCOM').info
print("Symbol", m['symbol'])
# how to get the current price during market hours?
# get the close price after market close
today = str(date.today())
data = yf.download('FCOM', today)
closing_price = data['Close'].iloc[-1]
Ticker
download()
Provides both closing and adjusted closing price, unlike Ticker history()
.