def start( self, # type: HummingbotApplication log_level: Optional[str] = None): if threading.current_thread() != threading.main_thread(): self.ev_loop.call_soon_threadsafe(self.start, log_level) return is_valid = self.status() if not is_valid: return if log_level is not None: init_logging("hummingbot_logs.yml", override_log_level=log_level.upper()) # If macOS, disable App Nap. if platform.system() == "Darwin": import appnope appnope.nope() # TODO add option to select data feed self.data_feed: DataFeedBase = CoinCapDataFeed.get_instance() self._initialize_notifiers() ExchangeRateConversion.get_instance().start() strategy_name = in_memory_config_map.get("strategy").value self.init_reporting_module() self._notify( f"\n Status check complete. Starting '{strategy_name}' strategy..." ) asyncio.ensure_future(self.start_market_making(strategy_name), loop=self.ev_loop)
def init_config(cls): try: if cls._data_feeds_override is None: cls._data_feeds = [CoinCapDataFeed.get_instance()] else: cls._data_feeds = cls._data_feeds_override # 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": 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._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 start(self, # type: HummingbotApplication log_level: Optional[str] = None): if threading.current_thread() != threading.main_thread(): self.ev_loop.call_soon_threadsafe(self.start, log_level) return if self.strategy_task is not None and not self.strategy_task.done(): self._notify('The bot is already running - please run "stop" first') return is_valid = self.status() if not is_valid: return strategy_file_path = in_memory_config_map.get("strategy_file_path").value init_logging("hummingbot_logs.yml", override_log_level=log_level.upper() if log_level else None, strategy_file_path=strategy_file_path) # If macOS, disable App Nap. if platform.system() == "Darwin": import appnope appnope.nope() # TODO add option to select data feed self.data_feed: DataFeedBase = CoinCapDataFeed.get_instance() self._initialize_notifiers() strategy_name = in_memory_config_map.get("strategy").value self._notify(f"\n Status check complete. Starting '{strategy_name}' strategy...") safe_ensure_future(self.start_market_making(strategy_name), loop=self.ev_loop)
async def update_asset_prices(self, id_asset_map: Dict[str, str]): try: await CoinCapDataFeed.get_instance().get_ready() all_ids = [ k for k, v in id_asset_map.items() if v in CoinCapDataFeed.get_instance().price_dict.keys() ] ids_chunks: List[List[str]] = [ all_ids[x:x + 70] for x in range(0, len(all_ids), 70) ] client: aiohttp.ClientSession = await self._http_client() price_url: str = f"{self.BASE_URL}/simple/price" price_dict: Dict[str, float] = {} for ids_chunk in ids_chunks: ids: str = ",".join(ids_chunk) params: Dict[str, str] = {"ids": ids, "vs_currencies": "usd"} try: async with client.request("GET", price_url, params=params) as resp: results: Dict[str, Dict[str, float]] = await resp.json() if 'error' in results: raise Exception(f"{results['error']}") for id, usd_price in results.items(): asset: str = id_asset_map[id].upper() price: float = float(usd_price.get("usd", 0.0)) price_dict[asset] = price except Exception as e: self.logger().warning( f"Coin Gecko API request failed. Exception: {str(e)}") raise e await asyncio.sleep(0.1) self._price_dict = price_dict except Exception: raise
async def start_check( self, # type: HummingbotApplication log_level: Optional[str] = None): if self.strategy_task is not None and not self.strategy_task.done(): self._notify( 'The bot is already running - please run "stop" first') return is_valid = await self.status_check_all(notify_success=False) if not is_valid: return init_logging( "hummingbot_logs.yml", override_log_level=log_level.upper() if log_level else None, strategy_file_path=self.strategy_file_name) # If macOS, disable App Nap. if platform.system() == "Darwin": import appnope appnope.nope() # TODO add option to select data feed self.data_feed: DataFeedBase = CoinCapDataFeed.get_instance() self._initialize_notifiers() self._notify( f"\nStatus check complete. Starting '{self.strategy_name}' strategy..." ) if global_config_map.get("paper_trade_enabled").value: self._notify( "\nPaper Trading ON: All orders are simulated, and no real orders are placed." ) await self.start_market_making(self.strategy_name)
def start(self, log_level: Optional[str] = None): is_valid = self.status() if not is_valid: return if log_level is not None: init_logging("hummingbot_logs.yml", override_log_level=log_level.upper()) # If macOS, disable App Nap. if platform.system() == "Darwin": import appnope appnope.nope() # TODO add option to select data feed self.data_feed: DataFeedBase = CoinCapDataFeed.get_instance() ExchangeRateConversion.get_instance().start() strategy_name = in_memory_config_map.get("strategy").value self.init_reporting_module() self.app.log( f"\n Status check complete. Starting '{strategy_name}' strategy..." ) asyncio.ensure_future(self.start_market_making(strategy_name))