def to_cryptocompare(self) -> str: cryptocompare_str = WORLD_TO_CRYPTOCOMPARE.get(self.identifier, self.identifier) # There is an asset which should not be queried in cryptocompare if cryptocompare_str is None: if self.identifier == 'MRS': raise UnsupportedAsset( 'Marginless is not in cryptocompare. Asking for MRS ' 'will return MARScoin', ) else: raise RuntimeError( f'Got {self.identifier} as a cryptocompare query but it is ' f'documented as returning None and is not handled', ) return cryptocompare_str
def process_asset( our_data: Dict[str, Dict[str, Any]], asset_symbol: str, paprika_coins_list: List[Dict[str, Any]], paprika: CoinPaprika, cmc_list: Optional[List[Dict[str, Any]]], cryptocompare_coins_map: Dict[str, Any], always_keep_our_time: bool, ) -> Dict[str, Any]: """ Process a single asset symbol. Compare to all external APIs and if there is no local data on the symbol query the user on which data to use for each asset attribute. """ token_address = None our_asset = our_data[asset_symbol] # Coin paprika does not have info on FIAT currencies if asset_symbol in FIAT_CURRENCIES: return our_data found_coin_id = find_paprika_coin_id(asset_symbol, paprika_coins_list) if found_coin_id: print(f'paprika id: {found_coin_id}') paprika_coin_data = paprika.get_coin_by_id(found_coin_id) paprika_token_address = get_paprika_data_eth_token_address( paprika_data=paprika_coin_data, asset_symbol=asset_symbol, ) check_paprika_token_address( paprika_token_address=paprika_token_address, given_token_address=token_address, asset_symbol=asset_symbol, ) else: paprika_coin_data = None cmc_coin_data = find_cmc_coin_data(asset_symbol, cmc_list) our_data = timerange_check( asset_symbol=asset_symbol, our_asset=our_asset, our_data=our_data, paprika_data=paprika_coin_data, cmc_data=cmc_coin_data, always_keep_our_time=always_keep_our_time, token_address=token_address, ) our_data = name_check( asset_symbol=asset_symbol, our_asset=our_asset, our_data=our_data, paprika_data=paprika_coin_data, cmc_data=cmc_coin_data, ) our_data = active_check( asset_symbol=asset_symbol, our_asset=our_asset, our_data=our_data, paprika_data=paprika_coin_data, cmc_data=cmc_coin_data, ) our_data = typeinfo_check( asset_symbol=asset_symbol, our_asset=our_asset, our_data=our_data, paprika_data=paprika_coin_data, cmc_data=cmc_coin_data, ) # add the symbol as an asset attribute in the data symbol = asset_symbol match = re.search('(.*)-\\d+', symbol) # If our key is a numbered key, like 'PAI-2', 'PAI-3' e.t.c. use the # non suffixed symbol, iow just 'PAI' if match: symbol = match.group(1) our_data[asset_symbol]['symbol'] = symbol # Make sure that the asset is also known to cryptocompare cryptocompare_symbol = WORLD_TO_CRYPTOCOMPARE.get(asset_symbol, asset_symbol) cryptocompare_problem = ( asset_symbol not in KNOWN_TO_MISS_FROM_CRYPTOCOMPARE and cryptocompare_symbol not in cryptocompare_coins_map) if cryptocompare_problem: print(f'Asset {asset_symbol} is not in cryptocompare') sys.exit(1) return our_data