Yahoo Finance API: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
 
(One intermediate revision by the same user not shown)
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("Close Price", m['regularMarketPreviousClose'])


# historical data, return a Pandas DataFrame.
print("Symbol", m['symbol'])
data = yf.download('FCOM', '2023-10-01', '2023-10-13')
 
# 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>
</syntaxhighlight>



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().