7

我有 ISIN、Ticker 符号(没有后缀,例如 Samsung005930和 not 005930.KS)和国家名称。当我访问雅虎财经网站时,我可以使用 ISIN 进行搜索,并获得我正在寻找的股票。

当我尝试通过调用 API 端点以编程方式执行此操作时,https://query2.finance.yahoo.com/v10/finance/quoteSummary/{ TickerSymbol }?modules=financialData它并不总是有效,因为在某些情况下缺少后缀。而且我还没有找到用 ISIN 查询的方法。

那么,如何使用 Yahoo Finance API 分别使用 ISIN、Ticker Symbol(无后缀)国家名称查找股票?

谢谢

4

1 回答 1

5

因此,正如您已经发现的那样,具有后缀对于从该(以及所有其他)端点检索数据是必要的。在向该端点发出请求之前,您可以做的是使用他们的搜索端点来查找具有适当后缀的符号:

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

而且数据...

{'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}

接下来,检索符号,然后发出下一个请求:

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}}
于 2020-06-25T14:18:16.140 回答