def test_init_config():
    config_path = get_fake_config_path()
    if os.path.isfile(config_path):
        os.remove(config_path)

    init_config(config_file=config_path,
                from_config_file=os.path.join(TEST_CONFIG_FOLDER, CONFIG_FILE))
    assert os.path.isfile(config_path)
    os.remove(config_path)
예제 #2
0
def _create_startup_config(logger):
    logger.info("Loading config files...")
    config = _create_configuration()
    if config.is_config_file_empty_or_missing():
        logger.info("No configuration found creating default configuration...")
        configuration_manager.init_config()
        config.read(should_raise=False)
    else:
        _read_config(config, logger)
        _validate_config(config, logger)
    return config
예제 #3
0
파일: cli.py 프로젝트: aplodismenty/Crybot
def start_octobot(args):
    logger = None
    try:
        if args.version:
            print(constants.LONG_VERSION)
            return

        logger = octobot_logger.init_logger()

        # Version
        logger.info("Version : {0}".format(constants.LONG_VERSION))

        # Current running environment
        try:
            logger.debug(
                f"Running on {os_util.get_current_platform()} with {os_util.get_octobot_type()}"
            )
        except Exception as e:
            logger.error(
                f"Impossible to identify the current running environment: {e}")

        # _check_public_announcements(logger)

        logger.info("Loading config files...")

        # configuration loading
        config_path = configuration.get_user_config()
        config = configuration.Configuration(
            config_path, common_constants.USER_PROFILES_FOLDER,
            constants.CONFIG_FILE_SCHEMA, constants.PROFILE_FILE_SCHEMA)
        if config.are_profiles_empty_or_missing():
            logger.info("No profile found creating default profile...")
            configuration_manager.init_default_profile()
        if config.is_config_file_empty_or_missing():
            logger.info(
                "No configuration found creating default configuration...")
            configuration_manager.init_config()
            config.read(should_raise=False)
        else:
            config.read(should_raise=False, fill_missing_fields=True)
            try:
                config.validate()
            except Exception as err:
                if configuration_manager.migrate_from_previous_config(config):
                    logger.info(
                        "Your configuration has been migrated into the newest format."
                    )
                else:
                    logger.error(
                        "OctoBot can't repair your config.json file: invalid format: "
                        + str(err))
                    raise errors.ConfigError from err
        configuration_manager.config_health_check(config, args.backtesting)

        if not config.is_loaded():
            raise errors.ConfigError

        # Handle utility methods before bot initializing if possible
        if args.encrypter:
            commands.exchange_keys_encrypter()
            return
        update_config_with_args(args, config, logger)

        if args.backtesting:
            bot = octobot_backtesting.OctoBotBacktestingFactory(
                config,
                run_on_common_part_only=not args.whole_data_range,
                enable_join_timeout=args.enable_backtesting_timeout)
        else:
            bot = octobot_class.OctoBot(
                config, reset_trading_history=args.reset_trading_history)
        octobot.set_bot(bot)
        if args.identifier:
            # set community identifier
            bot.community_auth.identifier = args.identifier[0]

        if args.update:
            return commands.update_bot(bot.octobot_api)

        _log_terms_if_unaccepted(config, logger)

        # Add tentacles folder to Python path
        sys.path.append(os.path.realpath(os.getcwd()))

        if not (os.path.isfile(tentacles_manager_constants.
                               USER_REFERENCE_TENTACLE_CONFIG_FILE_PATH)
                and tentacles_manager_api.load_tentacles(verbose=True)):
            logger.info(
                "OctoBot tentacles can't be found or are damaged. Installing default tentacles ..."
            )
            commands.run_tentacles_installation()
            # reload profiles
            config.load_profiles()
            # reload tentacles
            tentacles_manager_api.load_tentacles(verbose=True)

        # Clear community cache
        bot.community_auth.clear_cache()

        if args.strategy_optimizer:
            commands.start_strategy_optimizer(config, args.strategy_optimizer)
            return

        # In those cases load OctoBot
        _disable_interface_from_param("telegram", args.no_telegram, logger)
        _disable_interface_from_param("web", args.no_web, logger)

        commands.run_bot(bot, logger)

    except errors.ConfigError:
        logger.error("OctoBot can't start without a valid " +
                     common_constants.CONFIG_FILE + " configuration file." +
                     "\nYou can use " + constants.DEFAULT_CONFIG_FILE +
                     " as an example to fix it.")
        os._exit(-1)

    except errors.NoProfileError:
        logger.error(
            "OctoBot can't start without a valid default profile configuration\nYou can use "
            + constants.DEFAULT_PROFILE_FILE + " as an example to fix it.")
        os._exit(-1)

    except ModuleNotFoundError as e:
        if 'tentacles' in str(e):
            logger.error(
                "Impossible to start OctoBot, tentacles are missing.\nTo install tentacles, "
                "please use the following command:\nstart.py tentacles --install --all"
            )
        else:
            logger.exception(e)
        os._exit(-1)

    except errors.ConfigEvaluatorError:
        logger.error(
            "OctoBot can't start without a valid  configuration file.\n"
            "This file is generated on tentacle "
            "installation using the following command:\nstart.py tentacles --install --all"
        )
        os._exit(-1)

    except errors.ConfigTradingError:
        logger.error(
            "OctoBot can't start without a valid configuration file.\n"
            "This file is generated on tentacle "
            "installation using the following command:\nstart.py tentacles --install --all"
        )
        os._exit(-1)