async def _update_market(self):
        """
        Loads all the cryptocurrencies that exist in the market

        @return - list of crypto-currencies
        """
        try:
            retry_count = 0
            market_stats = self.coin_market.fetch_coinmarket_stats()
            currency_data = self.coin_market.fetch_currency_data()
            while market_stats is None or currency_data is None:
                if retry_count >= 10:
                    msg = ("Max retry attempts reached. Please make "
                           "sure you're able to access coinmarketcap "
                           "through their website, check if the coinmarketapi "
                           "is down, and check if "
                           "anything is blocking you from requesting "
                           "data.")
                    raise CoreFunctionalityException(msg)
                logger.warning("Retrying to get data..")
                if market_stats is None:
                    market_stats = self.coin_market.fetch_coinmarket_stats()
                if currency_data is None:
                    currency_data = self.coin_market.fetch_currency_data()
                retry_count += 1
                await asyncio.sleep(5)
            market_dict = {}
            for currency in currency_data['data']:
                market_dict[currency['slug']] = currency
            await self._get_top_five(currency_data['data'])
            self.market_stats = market_stats
            self.market_list = market_dict
        except Exception as e:
            print("Failed to update market. See error.log.")
            logger.error("Exception: {}".format(str(e)))
예제 #2
0
    def load_all_acronyms(self):
        """
        Loads all available acronyms for cryptocurrencies

        @return - all cryptocurrency acronyms
        """
        try:
            acronym_list = {}
            duplicate_count = 0
            data = self.fetch_currency_data(load_all=True)
            for currency in data:
                if currency['symbol'] in acronym_list:
                    duplicate_count += 1
                    logger.warning(
                        "Found duplicate acronym. Creating seperate "
                        "separate definition...")
                    if currency['symbol'] not in acronym_list[
                            currency['symbol']]:
                        acronym_list[currency['symbol'] +
                                     str(1)] = acronym_list[currency['symbol']]
                        acronym_list[currency['symbol']] = (
                            "Duplicate acronyms "
                            "found. Possible "
                            "searches are:\n"
                            "{}1 ({})\n".format(
                                currency['symbol'],
                                acronym_list[currency['symbol']]))
                    dupe_acronym = re.search('\\d+',
                                             acronym_list[currency['symbol']])
                    dupe_num = str(
                        int(dupe_acronym.group(len(dupe_acronym.group()) -
                                               1)) + 1)
                    dupe_key = currency['symbol'] + dupe_num
                    acronym_list[dupe_key] = currency['id']
                    acronym_list[currency['symbol']] = (
                        acronym_list[currency['symbol']] +
                        "{} ({})".format(dupe_key, currency['id']))
                    dupe_msg = "Created duplicate acronym: {} ({})".format(
                        dupe_key, currency['id'])
                    logger.info(dupe_msg)
                else:
                    acronym_list[currency['symbol']] = currency['id']
            return acronym_list, duplicate_count
        except Exception as e:
            raise CoinMarketException(
                "Failed to load all acronyms: {}".format(e))