def download_prices(self): url = "http://www.google.com/finance/option_chain?q=%s&expd=%d&expm=%d&expy=%d&output=json" % \ (self.parent_stock.get_symbol_for_url(), self.expiryDay, self.expiryMonth, self.expiryYear) raw_data = fix_output(urllib2.urlopen(url).read()) option_data = byteify(json.loads(raw_data)) self.calls = self._get_prices('call', option_data) self.puts = self._get_prices('put', option_data)
def __download_expiry_dates(self): option_dates = None base_url = "http://www.google.com/finance/option_chain?q=%s&output=json" for market in self.MARKETS: adjusted_symbol = self.symbol if len(market) > 0: # add the market as a prefix separated by a colon; ex. 'NYSE:V' adjusted_symbol = '%s%%3A%s' % (market, self.symbol) url = base_url % adjusted_symbol logger.info('Attempting to get expiry dates for [%s] with URL: [%s]' % (self.symbol, url)) raw_data = fix_output(urllib2.urlopen(url).read()) option_dates = byteify(json.loads(raw_data)) if 'expirations' in option_dates: self.symbol_for_url = adjusted_symbol break logger.info('No expiry dates found for symbol [%s] with market [%s]' % (self.symbol, market)) option_dates = None return option_dates