Yahoo Finance API: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
(Created page with "=External= * https://towardsdatascience.com/python-how-to-get-live-market-data-less-than-0-1-second-lag-c85ee280ed93 =Internal= * Financial_Data_Science#Yahoo_Finance_API|Fi...")
 
 
(16 intermediate revisions by the same user not shown)
Line 1: Line 1:
=External=
=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://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=
=Internal=
* [[Financial_Data_Science#Yahoo_Finance_API|Financial Data ScienceI]]
* [[Financial_Data_Science#Yahoo_Finance_API|Financial Data Science]]


=Overview=
=Overview=
Line 10: Line 14:
pip3 install yfinance
pip3 install yfinance
</syntaxhighlight>
</syntaxhighlight>
=Usage=
<font color=darkkhaki>Refactor to get the current price during market hours and get the closing price after market.</font>
<syntaxhighlight lang='py'>
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? Is there a Ticker 'currentPrice' or 'regularMarketPrice'?
# get the close price after market close
today = str(date.today())
data = yf.download('FCOM', today)
closing_price = data['Close'].iloc[-1]
</syntaxhighlight>
=Ticker=
{{Internal|Yahoo Finance API Ticker|Ticker}}
=<tt>download()</tt>=
Provides both closing and [https://pkb.feodorov.com/index.php/Trading#Adjusted_Closing adjusted closing] price, unlike [[Yahoo Finance API Ticker|Ticker]] <code>history()</code>.

Latest revision as of 07:23, 14 October 2023

External

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? Is there a Ticker 'currentPrice' or 'regularMarketPrice'?

# get the close price after market close
today = str(date.today())
data = yf.download('FCOM', today)
closing_price = data['Close'].iloc[-1]

Ticker

Ticker

download()

Provides both closing and adjusted closing price, unlike Ticker history().