Yahoo Finance API

From NovaOrdis Knowledge Base
Jump to navigation Jump to search

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