pkout / yahoo_finance_api2

API to interact with Yahoo Finance
MIT License
39 stars 13 forks source link

KeyError: 'adj_close' #7

Closed takuta98 closed 3 years ago

takuta98 commented 3 years ago

When I ran the following code on version 0.0.10, I got an error. Why?

import sys
from yahoo_finance_api2 import share
from yahoo_finance_api2.exceptions import YahooFinanceError

my_share = share.Share('MSFT')
symbol_data = None

try:
    symbol_data = my_share.get_historical(share.PERIOD_TYPE_DAY,
                                          10,
                                          share.FREQUENCY_TYPE_MINUTE,
                                          5)
except YahooFinanceError as e:
    print(e.message)
    sys.exit(1)

print(symbol_data)
---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
<ipython-input-1-982e03b83e66> in <module>()
     10                                           10,
     11                                           share.FREQUENCY_TYPE_MINUTE,
---> 12                                           5)
     13 except YahooFinanceError as e:
     14     print(e.message)

/usr/local/lib/python3.7/dist-packages/yahoo_finance_api2/share.py in get_historical(self, period_type, period, frequency_type, frequency)
     52             'low': data['indicators']['quote'][0]['low'],
     53             'close': data['indicators']['quote'][0]['close'],
---> 54             'adj_close': data['indicators']['quote'][0]['adj_close'],
     55             'volume': data['indicators']['quote'][0]['volume']
     56         }

KeyError: 'adj_close'
pkout commented 3 years ago

I just removed the offending code. It came from a pull request this weekend.