async def main_async(client_config_map: ClientConfigAdapter): await create_yml_files_legacy() # This init_logging() call is important, to skip over the missing config warnings. init_logging("hummingbot_logs.yml", client_config_map) AllConnectorSettings.initialize_paper_trade_settings( client_config_map.paper_trade.paper_trade_exchanges) hb = HummingbotApplication.main_application(client_config_map) # The listener needs to have a named variable for keeping reference, since the event listener system # uses weak references to remove unneeded listeners. start_listener: UIStartListener = UIStartListener(hb) hb.app.add_listener(HummingbotUIEvent.Start, start_listener) tasks: List[Coroutine] = [ hb.run(), start_existing_gateway_container(client_config_map) ] if client_config_map.debug_console: if not hasattr(__builtins__, "help"): import _sitebuiltins __builtins__.help = _sitebuiltins._Helper() from hummingbot.core.management.console import start_management_console management_port: int = detect_available_port(8211) tasks.append( start_management_console(locals(), host="localhost", port=management_port)) await safe_gather(*tasks)
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 quick_start(args): config_file_name = args.config_file_name wallet = args.wallet password = args.config_password if args.auto_set_permissions is not None: autofix_permissions(args.auto_set_permissions) if password is not None and not Security.login(password): logging.getLogger().error("Invalid password.") return await Security.wait_til_decryption_done() await create_yml_files() init_logging("hummingbot_logs.yml") read_system_configs_from_yml() hb = HummingbotApplication.main_application() # Todo: validate strategy and config_file_name before assinging if config_file_name is not None: hb.strategy_file_name = config_file_name hb.strategy_name = update_strategy_config_map_from_file( os.path.join(CONF_FILE_PATH, config_file_name)) # To ensure quickstart runs with the default value of False for kill_switch_enabled if not present if not global_config_map.get("kill_switch_enabled"): global_config_map.get("kill_switch_enabled").value = False if wallet and password: global_config_map.get("ethereum_wallet").value = wallet if hb.strategy_name and hb.strategy_file_name: if not all_configs_complete(hb.strategy_name): hb.status() with patch_stdout(log_field=hb.app.log_field): dev_mode = check_dev_mode() if dev_mode: hb.app.log( "Running from dev branches. Full remote logging will be enabled." ) log_level = global_config_map.get("log_level").value init_logging("hummingbot_logs.yml", override_log_level=log_level, dev_mode=dev_mode) if hb.strategy_file_name is not None and hb.strategy_name is not None: await write_config_to_yml(hb.strategy_name, hb.strategy_file_name) hb.start(log_level) tasks: List[Coroutine] = [hb.run()] if global_config_map.get("debug_console").value: management_port: int = detect_available_port(8211) tasks.append( start_management_console(locals(), host="localhost", port=management_port)) await safe_gather(*tasks)
async def main(): await create_yml_files() # This init_logging() call is important, to skip over the missing config warnings. init_logging("hummingbot_logs.yml") read_configs_from_yml() if __name__ == '__main__': hb = HummingbotApplication.main_application() with patch_stdout(log_field=hb.app.log_field): dev_mode = check_dev_mode() if dev_mode: hb.app.log( "Running from dev branches. Full remote logging will be enabled." ) init_logging( "hummingbot_logs.yml", override_log_level=global_config_map.get("log_level").value, dev_mode=dev_mode) tasks: List[Coroutine] = [hb.run()] if global_config_map.get("debug_console").value: management_port: int = detect_available_port(8211) tasks.append( start_management_console(locals(), host="localhost", port=management_port)) await asyncio.gather(*tasks)
async def main(): await create_yml_files() # This init_logging() call is important, to skip over the missing config warnings. init_logging("hummingbot_logs.yml") read_system_configs_from_yml() hb = HummingbotApplication.main_application() with patch_stdout(log_field=hb.app.log_field): dev_mode = check_dev_mode() if dev_mode: hb.app.log("Running from dev branches. Full remote logging will be enabled.") init_logging("hummingbot_logs.yml", override_log_level=global_config_map.get("log_level").value, dev_mode=dev_mode) tasks: List[Coroutine] = [hb.run()] if global_config_map.get("debug_console").value: if not hasattr(__builtins__, "help"): import _sitebuiltins __builtins__.help = _sitebuiltins._Helper() from hummingbot.core.management.console import start_management_console management_port: int = detect_available_port(8211) tasks.append(start_management_console(locals(), host="localhost", port=management_port)) await safe_gather(*tasks)
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)
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() 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)
async def main(): chdir_to_data_directory() await create_yml_files() # This init_logging() call is important, to skip over the missing config warnings. init_logging("hummingbot_logs.yml") hb = HummingbotApplication.main_application() setHummingInstance(hb) read_configs_from_yml() ExchangeRateConversion.get_instance().start() with patch_stdout(log_field=hb.app.log_field): dev_mode = check_dev_mode() if dev_mode: hb.app.log( "Running from dev branches. Full remote logging will be enabled." ) init_logging( "hummingbot_logs.yml", override_log_level=global_config_map.get("log_level").value, dev_mode=dev_mode) tasks: List[Coroutine] = [hb.run(), sio.connect('ws://localhost:5000')] await safe_gather(*tasks)
async def start_check( self, # type: HummingbotApplication log_level: Optional[str] = None, restore: Optional[bool] = False): 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 if settings.required_rate_oracle: if not (await self.confirm_oracle_conversion_rate()): self._notify("The strategy failed to start.") return else: RateOracle.get_instance().start() is_valid = await self.status_check_all(notify_success=False) if not is_valid: self._notify("Status checks failed. Start aborted.") return if self._last_started_strategy_file != self.strategy_file_name: init_logging( "hummingbot_logs.yml", override_log_level=log_level.upper() if log_level else None, strategy_file_path=self.strategy_file_name) self._last_started_strategy_file = self.strategy_file_name # If macOS, disable App Nap. if platform.system() == "Darwin": import appnope appnope.nope() 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." ) for exchange in settings.required_exchanges: connector = str(exchange) status = get_connector_status(connector) # Display custom warning message for specific connectors warning_msg = warning_messages.get(connector, None) if warning_msg is not None: self._notify(f"\nConnector status: {status}\n" f"{warning_msg}") # Display warning message if the exchange connector has outstanding issues or not working elif status != "GREEN": self._notify( f"\nConnector status: {status}. This connector has one or more issues.\n" "Refer to our Github page for more info: https://github.com/coinalpha/hummingbot" ) await self.start_market_making(self.strategy_name, restore)
async def quick_start(): try: args = CmdlineParser().parse_args() strategy = args.strategy config_file_name = args.config_file_name wallet = args.wallet password = args.config_password await create_yml_files() init_logging("hummingbot_logs.yml") read_configs_from_yml() ExchangeRateConversion.get_instance().start() await ExchangeRateConversion.get_instance().wait_till_ready() hb = HummingbotApplication.main_application() in_memory_config_map.get("password").value = password in_memory_config_map.get("strategy").value = strategy in_memory_config_map.get("strategy").validate(strategy) in_memory_config_map.get("strategy_file_path").value = config_file_name in_memory_config_map.get("strategy_file_path").validate(config_file_name) # To ensure quickstart runs with the default value of False for kill_switch_enabled if not present if not global_config_map.get("kill_switch_enabled"): global_config_map.get("kill_switch_enabled").value = False if wallet and password: global_config_map.get("wallet").value = wallet hb.acct = unlock_wallet(public_key=wallet, password=password) if not hb.config_complete: config_map = load_required_configs() empty_configs = [key for key, config in config_map.items() if config.value is None and config.required] empty_config_description: str = "\n- ".join([""] + empty_configs) raise ValueError(f"Missing empty configs: {empty_config_description}\n") with patch_stdout(log_field=hb.app.log_field): dev_mode = check_dev_mode() if dev_mode: hb.app.log("Running from dev branches. Full remote logging will be enabled.") log_level = global_config_map.get("log_level").value init_logging("hummingbot_logs.yml", override_log_level=log_level, dev_mode=dev_mode, strategy_file_path=config_file_name) await write_config_to_yml() hb.start(log_level) tasks: List[Coroutine] = [hb.run()] if global_config_map.get("debug_console").value: management_port: int = detect_available_port(8211) tasks.append(start_management_console(locals(), host="localhost", port=management_port)) await safe_gather(*tasks) except Exception as e: # In case of quick start failure, start the bot normally to allow further configuration logging.getLogger().warning(f"Bot config incomplete: {str(e)}. Starting normally...") await normal_start()
def did_start_ui(self): self._stdout_redirect_context.enter_context( patch_stdout(log_field=self.log_field)) log_level = global_config_map.get("log_level").value init_logging("hummingbot_logs.yml", override_log_level=log_level) self.trigger_event(HummingbotUIEvent.Start, self)
async def quick_start(): try: args = CmdlineParser().parse_args() strategy = args.strategy config_file_name = args.config_file_name wallet = args.wallet wallet_password = args.wallet_password await create_yml_files() init_logging("hummingbot_logs.yml") read_configs_from_yml() hb = HummingbotApplication.main_application() in_memory_config_map.get("strategy").value = strategy in_memory_config_map.get("strategy").validate(strategy) in_memory_config_map.get("strategy_file_path").value = config_file_name in_memory_config_map.get("strategy_file_path").validate( config_file_name) if wallet and wallet_password: global_config_map.get("wallet").value = wallet hb.acct = unlock_wallet(public_key=wallet, password=wallet_password) if not hb.config_complete: empty_configs = hb._get_empty_configs() empty_config_description: str = "\n- ".join([""] + empty_configs) raise ValueError( f"Missing empty configs: {empty_config_description}\n") with patch_stdout(log_field=hb.app.log_field): dev_mode = check_dev_mode() if dev_mode: hb.app.log( "Running from dev branches. Full remote logging will be enabled." ) log_level = global_config_map.get("log_level").value init_logging("hummingbot_logs.yml", override_log_level=log_level, dev_mode=dev_mode) hb.start(log_level) tasks: List[Coroutine] = [hb.run()] if global_config_map.get("debug_console").value: management_port: int = detect_available_port(8211) tasks.append( start_management_console(locals(), host="localhost", port=management_port)) await asyncio.gather(*tasks) except Exception as e: # In case of quick start failure, start the bot normally to allow further configuration logging.getLogger().warning( f"Bot config incomplete: {str(e)}. Starting normally...") await normal_start()
async def quick_start(args: argparse.Namespace, secrets_manager: BaseSecretsManager): config_file_name = args.config_file_name client_config = load_client_config_map_from_file() if args.auto_set_permissions is not None: autofix_permissions(args.auto_set_permissions) if not Security.login(secrets_manager): logging.getLogger().error("Invalid password.") return await Security.wait_til_decryption_done() await create_yml_files_legacy() init_logging("hummingbot_logs.yml", client_config) await read_system_configs_from_yml() AllConnectorSettings.initialize_paper_trade_settings( client_config.paper_trade.paper_trade_exchanges) hb = HummingbotApplication.main_application() # Todo: validate strategy and config_file_name before assinging strategy_config = None if config_file_name is not None: hb.strategy_file_name = config_file_name strategy_config = await load_strategy_config_map_from_file( STRATEGIES_CONF_DIR_PATH / config_file_name) hb.strategy_name = (strategy_config.strategy if isinstance( strategy_config, BaseStrategyConfigMap) else strategy_config.get("strategy").value) hb.strategy_config_map = strategy_config if strategy_config is not None: if not all_configs_complete(strategy_config, hb.client_config_map): hb.status() # The listener needs to have a named variable for keeping reference, since the event listener system # uses weak references to remove unneeded listeners. start_listener: UIStartListener = UIStartListener(hb) hb.app.add_listener(HummingbotUIEvent.Start, start_listener) tasks: List[Coroutine] = [ hb.run(), start_existing_gateway_container(client_config) ] if client_config.debug_console: management_port: int = detect_available_port(8211) tasks.append( start_management_console(locals(), host="localhost", port=management_port)) await safe_gather(*tasks)
async def quick_start(args): config_file_name = args.config_file_name wallet = args.wallet password = args.config_password if args.auto_set_permissions is not None: autofix_permissions(args.auto_set_permissions) if password is not None and not Security.login(password): logging.getLogger().error("Invalid password.") return await Security.wait_til_decryption_done() await create_yml_files() init_logging("hummingbot_logs.yml") await read_system_configs_from_yml() AllConnectorSettings.initialize_paper_trade_settings( global_config_map.get("paper_trade_exchanges").value) hb = HummingbotApplication.main_application() # Todo: validate strategy and config_file_name before assinging if config_file_name is not None: hb.strategy_file_name = config_file_name hb.strategy_name = await update_strategy_config_map_from_file( os.path.join(CONF_FILE_PATH, config_file_name)) # To ensure quickstart runs with the default value of False for kill_switch_enabled if not present if not global_config_map.get("kill_switch_enabled"): global_config_map.get("kill_switch_enabled").value = False if wallet and password: global_config_map.get("ethereum_wallet").value = wallet if hb.strategy_name and hb.strategy_file_name: if not all_configs_complete(hb.strategy_name): hb.status() # The listener needs to have a named variable for keeping reference, since the event listener system # uses weak references to remove unneeded listeners. start_listener: UIStartListener = UIStartListener(hb) hb.app.add_listener(HummingbotUIEvent.Start, start_listener) tasks: List[Coroutine] = [hb.run()] if global_config_map.get("debug_console").value: management_port: int = detect_available_port(8211) tasks.append( start_management_console(locals(), host="localhost", port=management_port)) await safe_gather(*tasks)
async def main(): await create_yml_files() read_configs_from_yml() hb = HummingbotApplication() with patch_stdout(log_field=hb.app.log_field): init_logging("hummingbot_logs.yml", override_log_level=global_config_map.get("log_level").value) tasks: List[Coroutine] = [hb.run()] if global_config_map.get("debug_console").value: management_port: int = detect_available_port(8211) tasks.append(start_management_console(locals(), host="localhost", port=management_port)) await asyncio.gather(*tasks)
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()) ExchangeRateConversion.get_instance().start() strategy_name = in_memory_config_map.get("strategy").value self.init_reporting_module() self.app.log(f"Status check complete. Starting '{strategy_name}' strategy...") asyncio.ensure_future(self.start_market_making(strategy_name))
async def main(): await create_yml_files() init_logging("hummingbot_logs.yml") read_configs_from_yml() hb = HummingbotApplication.main_application() hb.acct = unlock_wallet(public_key=WALLET_PUBLIC_KEY, password=WALLET_PASSWORD) with patch_stdout(log_field=hb.app.log_field): init_logging("hummingbot_logs.yml", override_log_level=global_config_map.get("log_level").value) logging.getLogger().info("____DEV_MODE__start_directly__") in_memory_config_map.get("strategy").value = STRATEGY in_memory_config_map.get("strategy").validate(STRATEGY) in_memory_config_map.get("strategy_file_path").value = STRATEGY_PATH in_memory_config_map.get("strategy_file_path").validate(STRATEGY_PATH) global_config_map.get("wallet").value = WALLET_PUBLIC_KEY tasks: List[Coroutine] = [hb.run()] await asyncio.gather(*tasks)
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))
async def start_check(self, # type: HummingbotApplication log_level: Optional[str] = None, restore: Optional[bool] = False, strategy_file_name: 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 if settings.required_rate_oracle: # If the strategy to run requires using the rate oracle to find FX rates, validate there is a rate for # each configured token pair if not (await self.confirm_oracle_conversion_rate()): self.notify("The strategy failed to start.") return if strategy_file_name: file_name = strategy_file_name.split(".")[0] self.strategy_file_name = file_name self.strategy_name = file_name elif not await self.status_check_all(notify_success=False): self.notify("Status checks failed. Start aborted.") return if self._last_started_strategy_file != self.strategy_file_name: init_logging("hummingbot_logs.yml", override_log_level=log_level.upper() if log_level else None, strategy_file_path=self.strategy_file_name) self._last_started_strategy_file = self.strategy_file_name # If macOS, disable App Nap. if platform.system() == "Darwin": import appnope appnope.nope() self._initialize_notifiers() try: self._initialize_strategy(self.strategy_name) except NotImplementedError: self.strategy_name = None self.strategy_file_name = None self.notify("Invalid strategy. Start aborted.") raise if any([str(exchange).endswith("paper_trade") for exchange in settings.required_exchanges]): self.notify("\nPaper Trading Active: All orders are simulated and no real orders are placed.") for exchange in settings.required_exchanges: connector: str = str(exchange) status: str = get_connector_status(connector) warning_msg: Optional[str] = warning_messages.get(connector, None) # confirm gateway connection conn_setting: settings.ConnectorSetting = settings.AllConnectorSettings.get_connector_settings()[connector] if conn_setting.uses_gateway_generic_connector(): connector_details: Dict[str, Any] = conn_setting.conn_init_parameters() if connector_details: data: List[List[str]] = [ ["chain", connector_details['chain']], ["network", connector_details['network']], ["wallet_address", connector_details['wallet_address']] ] await UserBalances.instance().update_exchange_balance(connector) balances: List[str] = [ f"{str(PerformanceMetrics.smart_round(v, 8))} {k}" for k, v in UserBalances.instance().all_balances(connector).items() ] data.append(["balances", ""]) for bal in balances: data.append(["", bal]) wallet_df: pd.DataFrame = pd.DataFrame(data=data, columns=["", f"{connector} configuration"]) self.notify(wallet_df.to_string(index=False)) self.app.clear_input() self.placeholder_mode = True use_configuration = await self.app.prompt(prompt="Do you want to continue? (Yes/No) >>> ") self.placeholder_mode = False self.app.change_prompt(prompt=">>> ") if use_configuration in ["N", "n", "No", "no"]: return if use_configuration not in ["Y", "y", "Yes", "yes"]: self.notify("Invalid input. Please execute the `start` command again.") return # Display custom warning message for specific connectors elif warning_msg is not None: self.notify(f"\nConnector status: {status}\n" f"{warning_msg}") # Display warning message if the exchange connector has outstanding issues or not working elif not status.endswith("GREEN"): self.notify(f"\nConnector status: {status}. This connector has one or more issues.\n" "Refer to our Github page for more info: https://github.com/coinalpha/hummingbot") self.notify(f"\nStatus check complete. Starting '{self.strategy_name}' strategy...") await self.start_market_making(restore) # We always start the RateOracle. It is required for PNL calculation. RateOracle.get_instance().start()
# Dev environment. from os.path import join, realpath import sys sys.path.insert(0, realpath(join(__file__, "../../"))) import asyncio import errno import socket from typing import ( List, Coroutine ) # This init_logging() call is important, to skip over the missing config # warnings. from hummingbot import init_logging; init_logging("hummingbot_logs.yml") from hummingbot.cli.hummingbot_application import HummingbotApplication from hummingbot.cli.settings import ( global_config_map, create_yml_files, read_configs_from_yml ) from hummingbot.cli.ui.stdout_redirection import patch_stdout from hummingbot.management.console import start_management_console def detect_available_port(starting_port: int) -> int: with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s: current_port: int = starting_port while current_port < 65535: