Skip to content

Conversation

@hughdavenport
Copy link
Contributor

If for some reason the regularMarketOpen value is not retrieved in the summaryDetail, then still attempt to retrieve the regularMarketPrice

Example ticker of where this happens is 'ETHI.AX', which does not have anything in the summaryDetail. It also has the following error

{'err': {'elapsedTime': 10,
         'headers': {'age': '0',
                     'cache-control': 'max-age=0, private',
                     'content-length': '216',
                     'content-type': 'application/json;charset=utf-8',
                     'date': 'Wed, 16 Jun 2021 00:43:05 GMT',
                     'expires': '-1',
                     'server': 'envoy',
                     'vary': 'Origin',
                     'via': 'https/1.1 '
                            'media-router-api7007.prod.media.sg3.yahoo.com '
                            '(ApacheTrafficServer [cMsSf ])',
                     'x-envoy-upstream-service-time': '8',
                     'x-request-id': '2e424b2f-fb2b-447a-85b9-a09fc070c74f',
                     'x-yahoo-request-id': 'biaib19gcii8p',
                     'y-rid': 'biaib19gcii8p'},
         'requestUri': 'http://iquery.finance.yahoo.com:4080/v10/finance/quoteSummary/ETHI.AX?formatted=true&crumb=n21GbCuUO0I&lang=en-US&region=US&modules=defaultKeyStatistics%2CassetProfile%2CtopHoldings%2CfundPerformance%2CfundProfile%2CesgScores&ssl=true',
         'responseText': '{"quoteSummary":{"result":null,"error":{"code":"Not '
                         'Found","description":"No fundamentals data found for '
                         'any of the '
                         'summaryTypes=defaultKeyStatistics,assetProfile,topHoldings,fundPerformance,fundProfile,esgScores"}}}',
         'responseXML': None,
         'status': 404,
         'statusCode': 404,
         'statusText': 'Not Found'}}

The second commit fixes a test case of mine, there are some other fields that look like they are usually in the summaryDetail response. An example is currency.

It could be a better solution to detect when summaryDetail has failed, and in that case, use price instead (as it looks to have many of the same details). Some extras that seem to be only in the price dict are: currencySymbol, exchange, exchangeDataDelayedBy,exchangeName, longName, marketState, post*, pre*, quoteSourceName, quoteType, regularMarketChange*, regularMarketSource, regularMarketTime, shortName, symbol, underlyingSymbol.

If for some reason the regularMarketOpen value is not retrieved in the summaryDetail, then still attempt to retrieve the regularMarketPrice
For some tickers, such as `ETHI.AX`, the `summaryDetail` result is `None`. In this case, use the `price` dict if possible.
@silvavn
Copy link
Collaborator

silvavn commented Jun 24, 2021

@hughdavenport Could you please provide an explanation as:
This is the code that fails

put failing code here

this is the failing output:

put failing output here

After correction this is the code that I use to test

put good code here

And this is the good output

put good output here

@hughdavenport
Copy link
Contributor Author

This is the code that fails

import yfinance as yf
info=yf.Ticker('ETHI.AX').info
print(info)
print(info['regularMarketPrice'], info['currency'])

this is the failing output:

{'exchange': 'ASX', 'shortName': 'BETASUST ETF UNITS', 'longName': 'BetaShares Global Sustainability Leaders ETF', 'exchangeTimezoneName': 'Australia/Sydney', 'exchangeTimezoneShortName': 'AEST', 'isEsgPopulated': False, 'gmtOffSetMilliseconds': '36000000', 'quoteType': 'ETF', 'symbol': 'ETHI.AX', 'messageBoardId': 'finmb_413542169', 'market': 'au_market', 'err': {'elapsedTime': 11, 'headers': {'server': 'envoy', 'x-envoy-upstream-service-time': '10', 'via': 'https/1.1 media-router-api7013.prod.media.sg3.yahoo.com (ApacheTrafficServer [cMsSf ])', 'content-type': 'application/json;charset=utf-8', 'x-request-id': 'd2e2329d-1921-40fd-bdc5-cdfb596103c0', 'date': 'Thu, 24 Jun 2021 03:06:46 GMT', 'cache-control': 'max-age=0, private', 'vary': 'Origin', 'expires': '-1', 'y-rid': 'ch9shbhgd7tm6', 'content-length': '216', 'x-yahoo-request-id': 'ch9shbhgd7tm6', 'age': '0'}, 'requestUri': 'http://iquery.finance.yahoo.com:4080/v10/finance/quoteSummary/ETHI.AX?formatted=true&crumb=ncnmh457iYT&lang=en-US&region=US&modules=defaultKeyStatistics%2CassetProfile%2CtopHoldings%2CfundPerformance%2CfundProfile%2CesgScores&ssl=true', 'responseText': '{"quoteSummary":{"result":null,"error":{"code":"Not Found","description":"No fundamentals data found for any of the summaryTypes=defaultKeyStatistics,assetProfile,topHoldings,fundPerformance,fundProfile,esgScores"}}}', 'responseXML': None, 'status': 404, 'statusCode': 404, 'statusText': 'Not Found'}, 'logo_url': ''}
Traceback (most recent call last):
  File "<string>", line 1, in <module>
KeyError: 'regularMarketPrice'

After correction this is the code that I use to test

import yfinance as yf
info=yf.Ticker('ETHI.AX').info
print(info)
print(info['regularMarketPrice'], info['currency'])

And this is the good output

{'exchange': 'ASX', 'shortName': 'BETASUST ETF UNITS', 'longName': 'BetaShares Global Sustainability Leaders ETF', 'exchangeTimezoneName': 'Australia/Sydney', 'exchangeTimezoneShortName': 'AEST', 'isEsgPopulated': False, 'gmtOffSetMilliseconds': '36000000', 'quoteType': 'ETF', 'symbol': 'ETHI.AX', 'messageBoardId': 'finmb_413542169', 'market': 'au_market', 'err': {'elapsedTime': 10, 'headers': {'server': 'envoy', 'x-envoy-upstream-service-time': '9', 'via': 'https/1.1 media-router-api7013.prod.media.sg3.yahoo.com (ApacheTrafficServer [cMsSf ])', 'content-type': 'application/json;charset=utf-8', 'x-request-id': 'f0fb65e5-554f-42f0-ae7a-6ad933836ba4', 'date': 'Thu, 24 Jun 2021 03:09:38 GMT', 'cache-control': 'max-age=0, private', 'vary': 'Origin', 'expires': '-1', 'y-rid': 'cb0rn81gd7tri', 'content-length': '216', 'x-yahoo-request-id': 'cb0rn81gd7tri', 'age': '0'}, 'requestUri': 'http://iquery.finance.yahoo.com:4080/v10/finance/quoteSummary/ETHI.AX?formatted=true&crumb=cFMa5umEFjt&lang=en-US&region=US&modules=defaultKeyStatistics%2CassetProfile%2CtopHoldings%2CfundPerformance%2CfundProfile%2CesgScores&ssl=true', 'responseText': '{"quoteSummary":{"result":null,"error":{"code":"Not Found","description":"No fundamentals data found for any of the summaryTypes=defaultKeyStatistics,assetProfile,topHoldings,fundPerformance,fundProfile,esgScores"}}}', 'responseXML': None, 'status': 404, 'statusCode': 404, 'statusText': 'Not Found'}, 'quoteSourceName': 'Delayed Quote', 'regularMarketOpen': 12.59, 'averageDailyVolume3Month': 197006, 'regularMarketTime': 1624502782, 'volume24Hr': None, 'regularMarketDayHigh': 12.59, 'averageDailyVolume10Day': 198664, 'regularMarketChange': -0.06000042, 'currencySymbol': 'A$', 'regularMarketPreviousClose': 12.46, 'preMarketPrice': None, 'exchangeDataDelayedBy': 0, 'toCurrency': None, 'postMarketChange': None, 'postMarketPrice': None, 'exchangeName': 'ASX', 'preMarketChange': None, 'circulatingSupply': None, 'regularMarketDayLow': 12.39, 'priceHint': 2, 'currency': 'AUD', 'regularMarketPrice': 12.4, 'regularMarketVolume': 84064, 'lastMarket': None, 'regularMarketSource': 'DELAYED', 'openInterest': None, 'marketState': 'REGULAR', 'underlyingSymbol': None, 'marketCap': None, 'volumeAllCurrencies': None, 'strikePrice': None, 'maxAge': 1, 'fromCurrency': None, 'regularMarketChangePercent': -0.004815443, 'logo_url': ''}
12.4 AUD

@ranaroussi ranaroussi merged commit f39cd17 into ranaroussi:main Jul 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants