コード例 #1
0
 async def _unlock_wallet(
         self,  # type: HummingbotApplication
 ):
     """
     Special handler function that helps the user unlock an existing wallet, or redirect user to create a new wallet.
     """
     choice = await self.app.prompt(
         prompt=
         "Would you like to unlock your previously saved wallet? (y/n) >>> "
     )
     if choice.lower() in {"y", "yes"}:
         wallets = list_wallets()
         self._notify("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 = in_memory_config_map["password"].value
         try:
             acct = unlock_wallet(public_key=public_key, password=password)
             self._notify("Wallet %s unlocked" % (acct.address, ))
             self.acct = acct
             return self.acct.address
         except ValueError as err:
             if str(err) != "MAC mismatch":
                 raise err
             self._notify("The wallet was locked by a different password.")
             old_password = await self.app.prompt(
                 prompt="Please enter the password >>> ", is_password=True)
             try:
                 acct = unlock_wallet(public_key=public_key,
                                      password=old_password)
                 self._notify("Wallet %s unlocked" % (acct.address, ))
                 save_wallet(acct, password)
                 self._notify(
                     f"Wallet {acct.address} is now saved with your main password."
                 )
                 self.acct = acct
                 return self.acct.address
             except ValueError as err:
                 if str(err) != "MAC mismatch":
                     raise err
                 self._notify("Cannot unlock wallet. Please try again.")
                 return await self._unlock_wallet()
     else:
         value = await self._create_or_import_wallet()
         return value
コード例 #2
0
 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() in {"y", "yes"}:
         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
コード例 #3
0
ファイル: config_command.py プロジェクト: ASSETLID/Aych.bot
 async def _unlock_wallet(
         self,  # type: HummingbotApplication
 ):
     """
     Special handler function that helps the user unlock an existing wallet, or redirect user to create a new wallet.
     """
     choice = await self.app.prompt(
         prompt=
         "Would you like to unlock your previously saved wallet? (y/n) >>> "
     )
     if choice.lower() in {"y", "yes"}:
         wallets = list_wallets()
         self._notify("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._notify("Wallet %s unlocked" % (acct.address, ))
             self.acct = acct
             return self.acct.address
         except Exception:
             self._notify("Cannot unlock wallet. Please try again.")
             result = await self._unlock_wallet()
             return result
     else:
         value = await self._create_or_import_wallet()
         return value
コード例 #4
0
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()
コード例 #5
0
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()
コード例 #6
0
 async def _one_password_config(
         self,  # type: HummingbotApplication
 ):
     """
     Special handler function to handle one password unlocking all secure conf variable and wallets
         - let a user creates a new password if there is no existing encrypted_files or key_files.
         - verify the entered password is valid by trying to unlock files.
     """
     encrypted_files = list_encrypted_file_paths()
     wallets = list_wallets()
     password_valid = False
     err_msg = "Invalid password, please try again."
     if not encrypted_files and not wallets:
         password = await self.app.prompt(
             prompt="Enter your new password >>> ", is_password=True)
         re_password = await self.app.prompt(
             prompt="Please reenter your password >>> ", is_password=True)
         if password == re_password:
             password_valid = True
         else:
             err_msg = "Passwords entered do not match, please try again."
     else:
         password = await self.app.prompt(prompt="Enter your password >>> ",
                                          is_password=True)
         if encrypted_files:
             try:
                 decrypt_file(encrypted_files[0], password)
                 password_valid = True
             except ValueError as err:
                 if str(err) != "MAC mismatch":
                     raise err
         else:
             for wallet in wallets:
                 try:
                     unlock_wallet(public_key=wallet, password=password)
                     password_valid = True
                     break
                 except ValueError as err:
                     if str(err) != "MAC mismatch":
                         raise err
     if password_valid:
         return password
     else:
         self._notify(err_msg)
         return await self._one_password_config()
コード例 #7
0
ファイル: security.py プロジェクト: vinhtran91/beaxy-bot
 def login(cls, password):
     encrypted_files = list_encrypted_file_paths()
     wallets = list_wallets()
     if encrypted_files:
         try:
             decrypt_file(encrypted_files[0], password)
         except ValueError as err:
             if str(err) == "MAC mismatch":
                 return False
             raise err
     elif wallets:
         try:
             unlock_wallet(wallets[0], password)
         except ValueError as err:
             if str(err) == "MAC mismatch":
                 return False
             raise err
     Security.password = password
     coro = AsyncCallScheduler.shared_instance().call_async(cls.decrypt_all, timeout_seconds=30)
     safe_ensure_future(coro)
     return True
コード例 #8
0
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)
コード例 #9
0
ファイル: security.py プロジェクト: CoinAlpha/hummingbot
 def unlock_wallet(cls, public_key):
     if public_key not in cls._private_keys:
         cls._private_keys[public_key] = unlock_wallet(
             wallet_address=public_key, password=Security.password)
     return cls._private_keys[public_key]