JECSand / yahoofinancials

A powerful financial data module used for pulling data from Yahoo Finance. This module can pull fundamental and technical data for stocks, indexes, currencies, cryptos, ETFs, Mutual Funds, U.S. Treasuries, and commodity futures.
https://pypi.python.org/pypi/yahoofinancials
MIT License
899 stars 214 forks source link

How t oget instrument name from ticker #78

Open typhoon71 opened 4 years ago

typhoon71 commented 4 years ago

Is it possible to use yahoofinancials to get the name of a financial instrumento from the ticker?

For example, I know the ticker of an ETF is SWDA.MI How can I get iShares Core MSCI World UCITS ETF USD (Acc) (SWDA.MI)?

Is this possible at all? I'd like to d othis for funds, stocks, ... too. The relevant dat is available on the /quote page, so it should be feasible.

Thanks.

giteho commented 3 years ago

@typhoon71 What you look for is inside the JSON structure returned by get_stock_price_data(). The following sample code prints out the entire JSON structure and you can pick and choose whatever you need.

#!/usr/bin/env python3
import json
from yahoofinancials import YahooFinancials
yf = YahooFinancials( 'QQQ' )
stock_price = yf.get_stock_price_data()
# print out whole JSON structure
print( json.dumps(stock_price, indent=4) )
# print out the long name of the ticker
print( stock_price['QQQ']["longName"] )