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)
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 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 main(): await create_yml_files() # This init_logging() call is important, to skip over the missing config warnings. 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() 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)
async def _gateway_connect( self, # type: HummingbotApplication connector: str = None ): with begin_placeholder_mode(self): gateway_connections_conf: List[Dict[str, str]] = GatewayConnectionSetting.load() if connector is None: if len(gateway_connections_conf) < 1: self.notify("No existing connection.\n") else: connector_df: pd.DataFrame = build_connector_display(gateway_connections_conf) self.notify(connector_df.to_string(index=False)) else: # get available networks connector_configs: Dict[str, Any] = await GatewayHttpClient.get_instance().get_connectors() connector_config: List[Dict[str, Any]] = [ d for d in connector_configs["connectors"] if d["name"] == connector ] if len(connector_config) < 1: self.notify(f"No available blockchain networks available for the connector '{connector}'.") return available_networks: List[Dict[str, Any]] = connector_config[0]["available_networks"] trading_type: str = connector_config[0]["trading_type"][0] # ask user to select a chain. Automatically select if there is only one. chains: List[str] = [d['chain'] for d in available_networks] chain: str if len(chains) == 1: chain = chains[0] else: # chains as options while True: chain = await self.app.prompt( prompt=f"Which chain do you want {connector} to connect to?({', '.join(chains)}) >>> " ) if self.app.to_stop_config: self.app.to_stop_config = False return if chain in GATEWAY_CONNECTORS: break self.notify(f"{chain} chain not supported.\n") # ask user to select a network. Automatically select if there is only one. networks: List[str] = list( itertools.chain.from_iterable([d['networks'] for d in available_networks if d['chain'] == chain]) ) network: str if len(networks) == 1: network = networks[0] else: while True: self.app.input_field.completer.set_gateway_networks(networks) network = await self.app.prompt( prompt=f"Which network do you want {connector} to connect to? ({', '.join(networks)}) >>> " ) if self.app.to_stop_config: return if network in networks: break self.notify("Error: Invalid network") # get wallets for the selected chain wallets_response: List[Dict[str, Any]] = await GatewayHttpClient.get_instance().get_wallets() matching_wallets: List[Dict[str, Any]] = [w for w in wallets_response if w["chain"] == chain] wallets: List[str] if len(matching_wallets) < 1: wallets = [] else: wallets = matching_wallets[0]['walletAddresses'] # if the user has no wallet, ask them to select one if len(wallets) < 1: self.app.clear_input() self.placeholder_mode = True wallet_private_key = await self.app.prompt( prompt=f"Enter your {chain}-{network} wallet private key >>> ", is_password=True ) self.app.clear_input() if self.app.to_stop_config: return response: Dict[str, Any] = await GatewayHttpClient.get_instance().add_wallet( chain, network, wallet_private_key ) wallet_address: str = response["address"] # the user has a wallet. Ask if they want to use it or create a new one. else: # print table while True: use_existing_wallet: str = await self.app.prompt( prompt=f"Do you want to connect to {chain}-{network} with one of your existing wallets on " f"Gateway? (Yes/No) >>> " ) if self.app.to_stop_config: return if use_existing_wallet in ["Y", "y", "Yes", "yes", "N", "n", "No", "no"]: break self.notify("Invalid input. Please try again or exit config [CTRL + x].\n") self.app.clear_input() # they use an existing wallet if use_existing_wallet is not None and use_existing_wallet in ["Y", "y", "Yes", "yes"]: native_token: str = native_tokens[chain] wallet_table: List[Dict[str, Any]] = [] for w in wallets: balances: Dict[str, Any] = await GatewayHttpClient.get_instance().get_balances( chain, network, w, [native_token] ) wallet_table.append({"balance": balances['balances'][native_token], "address": w}) wallet_df: pd.DataFrame = build_wallet_display(native_token, wallet_table) self.notify(wallet_df.to_string(index=False)) self.app.input_field.completer.set_list_gateway_wallets_parameters(wallets_response, chain) while True: wallet_address: str = await self.app.prompt(prompt="Select a gateway wallet >>> ") if self.app.to_stop_config: return if wallet_address in wallets: self.notify(f"You have selected {wallet_address}") break self.notify("Error: Invalid wallet address") # they want to create a new wallet even though they have other ones else: while True: try: wallet_private_key: str = await self.app.prompt( prompt=f"Enter your {chain}-{network} wallet private key >>> ", is_password=True ) self.app.clear_input() if self.app.to_stop_config: return response: Dict[str, Any] = await GatewayHttpClient.get_instance().add_wallet( chain, network, wallet_private_key ) wallet_address = response["address"] break except Exception: self.notify("Error adding wallet. Check private key.\n") self.app.clear_input() # write wallets to Gateway connectors settings. GatewayConnectionSetting.upsert_connector_spec(connector, chain, network, trading_type, wallet_address) self.notify(f"The {connector} connector now uses wallet {wallet_address} on {chain}-{network}") # update AllConnectorSettings and fee overrides. AllConnectorSettings.create_connector_settings() AllConnectorSettings.initialize_paper_trade_settings(global_config_map.get("paper_trade_exchanges").value) await refresh_trade_fees_config() # Reload completer here to include newly added gateway connectors self.app.input_field.completer = load_completer(self)
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() 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)