def list_configs( self, # type: HummingbotApplication ): columns = ["Key", " Value"] data = [[cv.key, cv.value] for cv in global_config_map.values() if cv.key in global_configs_to_display and not cv.is_secure] df = map_df_to_str(pd.DataFrame(data=data, columns=columns)) self._notify("\nGlobal Configurations:") lines = [ " " + line for line in format_df_for_printout( df, max_col_width=50).split("\n") ] self._notify("\n".join(lines)) data = [[cv.key, cv.value] for cv in global_config_map.values() if cv.key in color_settings_to_display and not cv.is_secure] df = map_df_to_str(pd.DataFrame(data=data, columns=columns)) self._notify("\nColor Settings:") lines = [ " " + line for line in format_df_for_printout( df, max_col_width=50).split("\n") ] self._notify("\n".join(lines)) if self.strategy_name is not None: data = [[cv.printable_key or cv.key, cv.value] for cv in self.strategy_config_map.values() if not cv.is_secure] df = map_df_to_str(pd.DataFrame(data=data, columns=columns)) self._notify("\nStrategy Configurations:") lines = [ " " + line for line in format_df_for_printout( df, max_col_width=50).split("\n") ] self._notify("\n".join(lines))
def list_configs( self, # type: HummingbotApplication ): columns: List[str] = ["Key", "Current Value"] global_cvs: List[ConfigVar] = list( in_memory_config_map.values()) + list(global_config_map.values()) global_data: List[List[Any]] = [[ cv.key, len(str(cv.value)) * "*" if cv.is_secure else str(cv.value) ] for cv in global_cvs] global_df: pd.DataFrame = pd.DataFrame(data=global_data, columns=columns) self._notify("\nglobal configs:") self._notify(str(global_df)) strategy = in_memory_config_map.get("strategy").value if strategy: strategy_cvs: List[ConfigVar] = get_strategy_config_map( strategy).values() strategy_data: List[List[Any]] = [[ cv.key, len(str(cv.value)) * "*" if cv.is_secure else str(cv.value) ] for cv in strategy_cvs] strategy_df: pd.DataFrame = pd.DataFrame(data=strategy_data, columns=columns) self._notify(f"\n{strategy} strategy configs:") self._notify(str(strategy_df)) self._notify("\n")
def list_configs( self, # type: HummingbotApplication ): columns = ["Key", " Value"] data = [[cv.key, cv.value] for cv in global_config_map.values() if cv.key in global_configs_to_display and not cv.is_secure] df = pd.DataFrame(data=data, columns=columns) self._notify("\nGlobal Configurations:") lines = [ " " + line for line in df.to_string(index=False, max_colwidth=50).split("\n") ] self._notify("\n".join(lines)) if self.strategy_name is not None: data = [[cv.printable_key or cv.key, cv.value] for cv in self.strategy_config_map.values() if not cv.is_secure] df = pd.DataFrame(data=data, columns=columns) self._notify("\nStrategy Configurations:") lines = [ " " + line for line in df.to_string( index=False, max_colwidth=50).split("\n") ] self._notify("\n".join(lines))
async def api_keys(cls, exchange): await cls.wait_til_decryption_done() exchange_configs = [ c for c in global_config_map.values() if c.key in AllConnectorSettings.get_connector_settings() [exchange].config_keys and c.key in cls._secure_configs ] return {c.key: cls.decrypted_value(c.key) for c in exchange_configs}
async def api_keys(cls, exchange): await cls.wait_til_decryption_done() exchange_configs = [ c for c in global_config_map.values() if c.key in CONNECTOR_SETTINGS[exchange].config_keys and c.key in cls._secure_configs ] return {c.key: cls.decrypted_value(c.key) for c in exchange_configs}
def config_able_keys(self # type: HummingbotApplication ) -> List[str]: """ Returns a list of configurable keys - using config command, excluding exchanges api keys as they are set from connect command. """ keys = [c.key for c in global_config_map.values() if c.prompt is not None and not c.is_connect_key] if self.strategy_config_map is not None: keys += [c.key for c in self.strategy_config_map.values() if c.prompt is not None] return keys
async def connect_exchange(self, # type: HummingbotApplication exchange): self.app.clear_input() self.placeholder_mode = True self.app.hide_input = True if exchange == "kraken": self._notify("Reminder: Please ensure your Kraken API Key Nonce Window is at least 10.") exchange_configs = [c for c in global_config_map.values() if c.key in settings.CONNECTOR_SETTINGS[exchange].config_keys and c.is_connect_key] to_connect = True if Security.encrypted_file_exists(exchange_configs[0].key): await Security.wait_til_decryption_done() api_key_config = [c for c in exchange_configs if "api_key" in c.key] if api_key_config: api_key_config = api_key_config[0] api_key = Security.decrypted_value(api_key_config.key) prompt = f"Would you like to replace your existing {exchange} API key {api_key} (Yes/No)? >>> " else: prompt = f"Would you like to replace your existing {exchange_configs[0].key} (Yes/No)? >>> " answer = await self.app.prompt(prompt=prompt) if self.app.to_stop_config: self.app.to_stop_config = False return if answer.lower() not in ("yes", "y"): to_connect = False if to_connect: for config in exchange_configs: await self.prompt_a_config(config) if self.app.to_stop_config: self.app.to_stop_config = False return Security.update_secure_config(config.key, config.value) api_keys = await Security.api_keys(exchange) network_timeout = float(global_config_map["other_commands_timeout"].value) try: err_msg = await asyncio.wait_for( UserBalances.instance().add_exchange(exchange, **api_keys), network_timeout ) except asyncio.TimeoutError: self._notify("\nA network error prevented the connection to complete. See logs for more details.") self.placeholder_mode = False self.app.hide_input = False self.app.change_prompt(prompt=">>> ") raise if err_msg is None: self._notify(f"\nYou are now connected to {exchange}.") else: self._notify(f"\nError: {err_msg}") self.placeholder_mode = False self.app.hide_input = False self.app.change_prompt(prompt=">>> ")
def list_configs(self, # type: HummingbotApplication ): msg = "<b>Global Configurations:</b>\n" for cv in global_config_map.values(): if cv.key in global_configs_to_display and not cv.is_secure: msg += f"<pre> {cv.key}: {cv.value}</pre>\n" self._notify(msg) msg = "<b>Strategy Configurations:</b>\n" if self.strategy_name is not None: for cv in self.strategy_config_map.values(): if not cv.is_secure: msg += f"<pre> {cv.key}: {cv.value}</pre>\n" self._notify(msg)
async def connect_exchange( self, # type: HummingbotApplication exchange): self.app.clear_input() self.placeholder_mode = True self.app.hide_input = True if exchange == "kraken": self._notify( "Reminder: Please ensure your Kraken API Key Nonce Window is at least 10." ) exchange_configs = [ c for c in global_config_map.values() if c.key in settings.CONNECTOR_SETTINGS[exchange].config_keys and c.is_connect_key ] to_connect = True if Security.encrypted_file_exists(exchange_configs[0].key): await Security.wait_til_decryption_done() api_key_config = [ c for c in exchange_configs if "api_key" in c.key ][0] api_key = Security.decrypted_value(api_key_config.key) answer = await self.app.prompt( prompt= f"Would you like to replace your existing {exchange} API key " f"{api_key} (Yes/No)? >>> ") if self.app.to_stop_config: self.app.to_stop_config = False return if answer.lower() not in ("yes", "y"): to_connect = False if to_connect: for config in exchange_configs: await self.prompt_a_config(config) if self.app.to_stop_config: self.app.to_stop_config = False return Security.update_secure_config(config.key, config.value) api_keys = await Security.api_keys(exchange) err_msg = await UserBalances.instance().add_exchange( exchange, **api_keys) if err_msg is None: self._notify(f"\nYou are now connected to {exchange}.") else: self._notify(f"\nError: {err_msg}") self.placeholder_mode = False self.app.hide_input = False self.app.change_prompt(prompt=">>> ")
async def connect_exchange( self, # type: HummingbotApplication exchange): self.app.clear_input() self.placeholder_mode = True self.app.hide_input = True exchange_configs = [ c for c in global_config_map.values() if exchange in c.key and c.is_connect_key ] to_connect = True if Security.encrypted_file_exists(exchange_configs[0].key): await Security.wait_til_decryption_done() api_key_config = [ c for c in exchange_configs if "api_key" in c.key ][0] api_key = Security.decrypted_value(api_key_config.key) answer = await self.app.prompt( prompt= f"Would you like to replace your existing {exchange} API key " f"...{api_key[-4:]} (Yes/No)? >>> ") if answer.lower() not in ("yes", "y"): to_connect = False if to_connect: for config in exchange_configs: await self.prompt_a_config(config) Security.update_secure_config(config.key, config.value) api_keys = (await Security.api_keys(exchange)).values() err_msg = await UserBalances.instance().add_exchange( exchange, *api_keys) if err_msg is None: self._notify(f"\nYou are now connected to {exchange}.") else: self._notify(f"\nError: {err_msg}") self.placeholder_mode = False self.app.hide_input = False self.app.change_prompt(prompt=">>> ")
def list(self, obj: str): if obj == "wallets": wallets = list_wallets() if len(wallets) == 0: self.app.log( 'Wallet not available. Please configure your wallet (Enter "config wallet")' ) else: self.app.log('\n'.join(wallets)) elif obj == "exchanges": if len(EXCHANGES) == 0: self.app.log("No exchanges available") else: self.app.log('\n'.join(EXCHANGES)) elif obj == "configs": columns: List[str] = ["Key", "Current Value"] global_cvs: List[ConfigVar] = list( in_memory_config_map.values()) + list( global_config_map.values()) global_data: List[List[str, Any]] = [[ cv.key, len(str(cv.value)) * "*" if cv.is_secure else str(cv.value) ] for cv in global_cvs] global_df: pd.DataFrame = pd.DataFrame(data=global_data, columns=columns) self.app.log("\nglobal configs:") self.app.log(str(global_df)) strategy = in_memory_config_map.get("strategy").value if strategy: strategy_cvs: List[ConfigVar] = get_strategy_config_map( strategy).values() strategy_data: List[List[str, Any]] = [[ cv.key, len(str(cv.value)) * "*" if cv.is_secure else str(cv.value) ] for cv in strategy_cvs] strategy_df: pd.DataFrame = pd.DataFrame(data=strategy_data, columns=columns) self.app.log(f"\n{strategy} strategy configs:") self.app.log(str(strategy_df)) self.app.log("\n") elif obj == "trades": lines = [] if self.strategy is None: self.app.log("No strategy available, cannot show past trades.") else: if len(self.strategy.trades) > 0: df = Trade.to_pandas(self.strategy.trades) df_lines = str(df).split("\n") lines.extend(["", " Past trades:"] + [" " + line for line in df_lines]) else: lines.extend([" No past trades."]) self.app.log("\n".join(lines)) else: self.help("list")