async def single_prompt(cvar: ConfigVar):
     if cvar.required or single_key:
         if cvar.key == "strategy_file_path":
             val = await self._import_or_create_strategy_config()
         elif cvar.key == "wallet":
             wallets = list_wallets()
             if len(wallets) > 0:
                 val = await self._unlock_wallet()
             else:
                 val = await self._create_or_import_wallet()
             logging.getLogger("hummingbot.public_eth_address").info(
                 val)
         else:
             val = await self.app.prompt(prompt=cvar.prompt,
                                         is_password=cvar.is_secure)
         if not cvar.validate(val):
             self.app.log("%s is not a valid %s value" %
                          (val, cvar.key))
             val = await single_prompt(cvar)
     else:
         val = cvar.value
     if val is None or (isinstance(val, string_types)
                        and len(val) == 0):
         val = cvar.default
     return val
 async def _unlock_wallet(self):
     choice = await self.app.prompt(
         prompt=
         "Would you like to unlock your previously saved wallet? (y/n) >>> "
     )
     if choice.lower() == "y":
         wallets = list_wallets()
         self.app.log("Existing wallets:")
         self.list(obj="wallets")
         if len(wallets) == 1:
             public_key = wallets[0]
         else:
             public_key = await self.app.prompt(
                 prompt="Which wallet would you like to import ? >>> ")
         password = await self.app.prompt(prompt="Enter your password >>> ",
                                          is_password=True)
         try:
             acct = unlock_wallet(public_key=public_key, password=password)
             self.app.log("Wallet %s unlocked" % (acct.address, ))
             self.acct = acct
             return self.acct.address
         except Exception as e:
             self.app.log("Cannot unlock wallet. Please try again.")
             result = await self._unlock_wallet()
             return result
     else:
         value = await self._create_or_import_wallet()
         return value
Exemple #3
0
 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":
         self.app.log('\n'.join(load_required_configs().keys()))
     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")
Exemple #4
0
 async def inner_loop(_keys: List[str]):
     for key in _keys:
         current_strategy: str = in_memory_config_map.get(
             "strategy").value
         strategy_cm: Dict[str, ConfigVar] = get_strategy_config_map(
             current_strategy)
         if key in in_memory_config_map:
             cv: ConfigVar = in_memory_config_map.get(key)
         elif key in global_config_map:
             cv: ConfigVar = global_config_map.get(key)
         else:
             cv: ConfigVar = strategy_cm.get(key)
         if key == "wallet":
             wallets = list_wallets()
             if len(wallets) > 0:
                 value = await self._unlock_wallet()
             else:
                 value = await self._create_or_import_wallet()
             logging.getLogger("hummingbot.public_eth_address").info(
                 value)
         elif key == "strategy_file_path":
             value = await self._import_or_create_strategy_config()
         else:
             value = await single_prompt(cv)
         cv.value = parse_cvar_value(cv, value)
     if not self.config_complete:
         await inner_loop(self._get_empty_configs())
Exemple #5
0
 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":
         self.app.log('\n'.join(load_required_configs().keys()))
     else:
         self.help("list")
    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")
Exemple #7
0
 def _wallet_address_completer(self):
     return WordCompleter(list_wallets(), ignore_case=True)