Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Yahoo Finance: Search by ISIN or Ticker without Suffix

I have the ISIN, the Ticker symbol (without suffix, e.g. for Samsung 005930 and not 005930.KS) and the country name. When I go to the Yahoo Finance website I am able to search with the ISIN and I get the stock I am looking for.

When I try to do it programmatically by calling the API endpoint https://query2.finance.yahoo.com/v10/finance/quoteSummary/{ TickerSymbol }?modules=financialData it does not always work as the suffix is missing in certain cases. And I have not found a way to query with the ISIN.

So how can I find a stock using ISIN, Ticker Symbol (without suffix) respectively country name using the Yahoo Finance API?

Thanks

like image 220
quervernetzt Avatar asked Jun 25 '20 07:06

quervernetzt


1 Answers

So, as you've already discovered, having the suffix is necessary to retrieving data from that (and all other) endpoints. What you could do before making the request to that endpoint is use their search endpoint to find the symbol with the appropriate suffix:

import requests

url = "https://query2.finance.yahoo.com/v1/finance/search"
params = {'q': '005930', 'quotesCount': 1, 'newsCount': 0}

r = requests.get(url, params=params)
data = r.json()

And the data...

{'explains': [], 'count': 1, 'quotes': [{'exchange': 'KSC', 'shortname': 'SamsungElec', 'quoteType': 'EQUITY', 'symbol': '005930.KS', 'index': 'quotes', 'score': 23969.0, 'typeDisp': 'Equity', 'longname': 'Samsung Electronics Co., Ltd.', 'isYahooFinance': True}], 'news': [], 'nav': [], 'lists': [], 'totalTime': 9, 'timeTakenForQuotes': 7, 'timeTakenForNews': 0, 'timeTakenForAlgowatchlist': 1, 'timeTakenForPredefinedScreener': 1, 'timeTakenForCrunchbase': 0, 'timeTakenForNav': 1}

Next, retrieve the symbol and then make your next request:

symbol = data['quotes'][0]['symbol']
url = "https://query2.finance.yahoo.com/v10/finance/quoteSummary/{}".format(symbol)
r = requests.get(url, params={'modules': 'financialData'})
r.json()
{'quoteSummary': {'result': [{'financialData': {'maxAge': 86400, 'currentPrice': {'raw': 51900.0, 'fmt': '51,900.00'}, 'targetHighPrice': {'raw': 84000.0, 'fmt': '84,000.00'}, 'targetLowPrice': {'raw': 41000.0, 'fmt': '41,000.00'}, 'targetMeanPrice': {'raw': 54903.0, 'fmt': '54,903.00'}, 'targetMedianPrice': {'raw': 54000.0, 'fmt': '54,000.00'}, 'recommendationMean': {}, 'recommendationKey': 'none', 'numberOfAnalystOpinions': {'raw': 34, 'fmt': '34', 'longFmt': '34'}, 'totalCash': {'raw': 110830834155520, 'fmt': '110.83T', 'longFmt': '110,830,834,155,520'}, 'totalCashPerShare': {'raw': 16316.242, 'fmt': '16,316.24'}, 'ebitda': {'raw': 57610560602112, 'fmt': '57.61T', 'longFmt': '57,610,560,602,112'}, 'totalDebt': {'raw': 15665191714816, 'fmt': '15.67T', 'longFmt': '15,665,191,714,816'}, 'quickRatio': {'raw': 2.327, 'fmt': '2.33'}, 'currentRatio': {'raw': 2.883, 'fmt': '2.88'}, 'totalRevenue': {'raw': 233340506472448, 'fmt': '233.34T', 'longFmt': '233,340,506,472,448'}, 'debtToEquity': {'raw': 5.88, 'fmt': '5.88'}, 'revenuePerShare': {'raw': 34351.812, 'fmt': '34,351.81'}, 'returnOnAssets': {'raw': 0.049790002, 'fmt': '4.98%'}, 'returnOnEquity': {'raw': 0.08306, 'fmt': '8.31%'}, 'grossProfits': {'raw': 83161332000000, 'fmt': '83.16T', 'longFmt': '83,161,332,000,000'}, 'freeCashflow': {'raw': 13390567178240, 'fmt': '13.39T', 'longFmt': '13,390,567,178,240'}, 'operatingCashflow': {'raw': 51968483524608, 'fmt': '51.97T', 'longFmt': '51,968,483,524,608'}, 'earningsGrowth': {'raw': -0.159, 'fmt': '-15.90%'}, 'revenueGrowth': {'raw': 0.056, 'fmt': '5.60%'}, 'grossMargins': {'raw': 0.36016, 'fmt': '36.02%'}, 'ebitdaMargins': {'raw': 0.24689, 'fmt': '24.69%'}, 'operatingMargins': {'raw': 0.11991999, 'fmt': '11.99%'}, 'profitMargins': {'raw': 0.091230005, 'fmt': '9.12%'}, 'financialCurrency': 'KRW'}}], 'error': None}}
like image 185
putty Avatar answered Nov 02 '22 06:11

putty