def init_config(cls): try: if cls._data_feeds_override is None: cls._data_feeds = [CoinCapDataFeed.get_instance(), CoinGeckoDataFeed.get_instance()] else: cls._data_feeds = cls._data_feeds_override cls._default_data_feed = global_config_map["exchange_rate_default_data_feed"].value # Set default rate and source for token rates globally fetcher_global_config: List[List[str, str]] = global_config_map["exchange_rate_fetcher"].value or [] # Set rate and source for tokens that needs conversion, overwrites global config rate_conversion_config: List[List[str, str, str]] = global_config_map["exchange_rate_conversion"].value or [] if cls._exchange_rate_config_override is None: conversion_required = {e[0]: {"default": e[1], "source": e[2]} for e in rate_conversion_config} global_config = {e[0]: {"default": s_decimal_nan, "source": e[1]} for e in fetcher_global_config} else: conversion_required = cls._exchange_rate_config_override.get("conversion_required", {}) global_config = cls._exchange_rate_config_override.get("global_config", {}) cls._default_data_feed = cls._exchange_rate_config_override.get("default_data_feed", cls.DEFAULT_DATA_FEED_NAME) global_config = {k.upper(): v for k, v in global_config.items()} conversion_required = {k.upper(): v for k, v in conversion_required.items()} cls._exchange_rate_config = { "conversion_required": conversion_required, "global_config": {**global_config, **conversion_required} } cls._exchange_rate = {k: v["default"] for k, v in cls._exchange_rate_config["global_config"].items()} except Exception: cls.logger().error("Error initiating config for exchange rate conversion.", exc_info=True)
def test_get_rates(self): price_dict = CoinGeckoDataFeed.get_instance().price_dict self.assertTrue(len(price_dict) > 0) for asset, price in price_dict.items(): self.assertTrue(isinstance(price, float)) self.assertTrue(price_dict["BTC"] > 0) self.assertTrue(price_dict["ETH"] > 0) self.assertTrue(price_dict["ZRX"] > 0) self.assertTrue(price_dict["XLM"] > 0)
def tearDownClass(cls): async_run(CoinGeckoDataFeed.get_instance()._shared_client.close())
def setUpClass(cls): async_run(CoinGeckoDataFeed.get_instance().fetch_data())