def generate_symbols_json(self, filename=None, source_dates=False): symbol_map = {} if not source_dates: fn, r = download_exchange_symbols(self.name) with open(fn) as data_file: cached_symbols = json.load(data_file) response = self.api.returnticker() for exchange_symbol in response: base, market = self.sanitize_curency_symbol(exchange_symbol).split( '_') symbol = '{market}_{base}'.format(market=market, base=base) if (source_dates): start_date = self.get_symbol_start_date(exchange_symbol) else: try: start_date = cached_symbols[exchange_symbol]['start_date'] except KeyError: start_date = time.strftime('%Y-%m-%d') try: end_daily = cached_symbols[exchange_symbol]['end_daily'] except KeyError: end_daily = 'N/A' try: end_minute = cached_symbols[exchange_symbol]['end_minute'] except KeyError: end_minute = 'N/A' symbol_map[exchange_symbol] = dict( symbol=symbol, start_date=start_date, end_daily=end_daily, end_minute=end_minute, ) if (filename is None): filename = get_exchange_symbols_filename(self.name) with open(filename, 'w') as f: json.dump(symbol_map, f, sort_keys=True, indent=2, separators=(',', ':'))
def generate_symbols_json(self, filename=None, source_dates=False): symbol_map = {} if not source_dates: fn, r = download_exchange_symbols(self.name) with open(fn) as data_file: cached_symbols = json.load(data_file) response = self._request('symbols', None) for symbol in response.json(): if (source_dates): start_date = self.get_symbol_start_date(symbol) else: try: start_date = cached_symbols[symbol]['start_date'] except KeyError: start_date = time.strftime('%Y-%m-%d') try: end_daily = cached_symbols[symbol]['end_daily'] except KeyError: end_daily = 'N/A' try: end_minute = cached_symbols[symbol]['end_minute'] except KeyError: end_minute = 'N/A' symbol_map[symbol] = dict( symbol=symbol[:-3] + '_' + symbol[-3:], start_date=start_date, end_daily=end_daily, end_minute=end_minute, ) if (filename is None): filename = get_exchange_symbols_filename(self.name) with open(filename, 'w') as f: json.dump(symbol_map, f, sort_keys=True, indent=2, separators=(',', ':'))
def generate_symbols_json(self, filename=None): symbol_map = {} fn, r = download_exchange_symbols(self.name) with open(fn) as data_file: cached_symbols = json.load(data_file) markets = self.api.getmarkets() for market in markets: exchange_symbol = market['MarketName'] symbol = '{market}_{base}'.format( market=self.sanitize_curency_symbol(market['MarketCurrency']), base=self.sanitize_curency_symbol(market['BaseCurrency'])) try: end_daily = cached_symbols[exchange_symbol]['end_daily'] except KeyError as e: end_daily = 'N/A' try: end_minute = cached_symbols[exchange_symbol]['end_minute'] except KeyError as e: end_minute = 'N/A' symbol_map[exchange_symbol] = dict( symbol=symbol, start_date=pd.to_datetime(market['Created'], utc=True).strftime("%Y-%m-%d"), end_daily=end_daily, end_minute=end_minute, ) if (filename is None): filename = get_exchange_symbols_filename(self.name) with open(filename, 'w') as f: json.dump(symbol_map, f, sort_keys=True, indent=2, separators=(',', ':'))