Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Yahoo data source seems to not be working - any idea how to rectify this? #3

Open
GlobalBritain opened this issue Jul 17, 2021 · 2 comments

Comments

@GlobalBritain
Copy link

GlobalBritain commented Jul 17, 2021

Any idea how to rectify the below?

Processing data for stock: SCT.L
---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
<ipython-input-41-c0f85326750e> in <module>
      1 tf = MyTradingFunctions()
      2 tsParams = MyTradingParams(tf)
----> 3 tradingSystem = TradingSystem(tsParams)
      4 results = tradingSystem.startTrading()

~\Anaconda3\envs\Portfolio 2\lib\site-packages\backtester\trading_system.py in __init__(self, tsParams)
     33         self.executionSystem = None
     34         self.orderPlacer = None
---> 35         self.dataParser = self.tsParams.getDataParser()
     36         self.executionSystem = self.tsParams.getExecutionSystem()
     37         self.orderPlacer = self.tsParams.getOrderPlacer()

<ipython-input-37-8cd4a1c6cc78> in getDataParser(self)
     14         '''
     15         instrumentIds = self.__tradingFunctions.getSymbolsToTrade()
---> 16         return YahooStockDataSource(
     17             cachedFolderName = 'historicalData/',
     18             dataSetId = self.__dataSetId,

~\Anaconda3\envs\Portfolio 2\lib\site-packages\backtester\dataSource\yahoo_data_source.py in __init__(self, cachedFolderName, dataSetId, instrumentIds, startDateStr, endDateStr, event, adjustPrice, downloadId, liveUpdates, pad)
    117         self.event = event
    118         if liveUpdates:
--> 119             self._allTimes, self._groupedInstrumentUpdates = self.getGroupedInstrumentUpdates()
    120             self.processGroupedInstrumentUpdates()
    121             self._bookDataFeatureKeys = self.__bookDataByFeature.keys()

~\Anaconda3\envs\Portfolio 2\lib\site-packages\backtester\dataSource\data_source.py in getGroupedInstrumentUpdates(self)
     65             print('Processing data for stock: %s' % (instrumentId))
     66             fileName = self.getFileName(instrumentId)
---> 67             if not self.downloadAndAdjustData(instrumentId, fileName):
     68                 continue
     69             with open(fileName) as f:

~\Anaconda3\envs\Portfolio 2\lib\site-packages\backtester\dataSource\yahoo_data_source.py in downloadAndAdjustData(self, instrumentId, fileName)
    131     def downloadAndAdjustData(self, instrumentId, fileName):
    132         if not os.path.isfile(fileName):
--> 133             if not downloadFileFromYahoo(self._startDate, self._endDate, instrumentId, fileName):
    134                 logError('Skipping %s:' % (instrumentId))
    135                 return False

~\Anaconda3\envs\Portfolio 2\lib\site-packages\backtester\dataSource\data_source_utils.py in downloadFileFromYahoo(startDate, endDate, instrumentId, fileName, event)
     28 def downloadFileFromYahoo(startDate, endDate, instrumentId, fileName, event='history'):
     29     logInfo('Downloading %s' % fileName)
---> 30     cookie, crumb = getCookieForYahoo(instrumentId)
     31     start = int(mktime(startDate.timetuple()))
     32     end = int(mktime(endDate.timetuple()))

~\Anaconda3\envs\Portfolio 2\lib\site-packages\backtester\dataSource\data_source_utils.py in getCookieForYahoo(instrumentId)
     15     req = requests.get(url)
     16     txt = req.content
---> 17     cookie = req.cookies['B']
     18     pattern = re.compile('.*"CrumbStore":\{"crumb":"(?P<crumb>[^"]+)"\}')
     19 

~\Anaconda3\envs\Portfolio 2\lib\site-packages\requests\cookies.py in __getitem__(self, name)
    326         .. warning:: operation is O(n), not O(1).
    327         """
--> 328         return self._find_no_duplicates(name)
    329 
    330     def __setitem__(self, name, value):

~\Anaconda3\envs\Portfolio 2\lib\site-packages\requests\cookies.py in _find_no_duplicates(self, name, domain, path)
    397         if toReturn:
    398             return toReturn
--> 399         raise KeyError('name=%r, domain=%r, path=%r' % (name, domain, path))
    400 
    401     def __getstate__(self):

KeyError: "name='B', domain=None, path=None"
@charlesschaefer
Copy link

Hi @GlobalBritain! Same error here.

I've just created a PR with the correction...

#4

@ggardiakos
Copy link

Hi @GlobalBritain! Same error here.

I've just created a PR with the correction...

#4

GOAT

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

No branches or pull requests

3 participants