Пример #1
0
def _create_configuration():
    config_path = configuration.get_user_config()
    config = configuration.Configuration(config_path,
                                         common_constants.USER_PROFILES_FOLDER,
                                         constants.CONFIG_FILE_SCHEMA,
                                         constants.PROFILE_FILE_SCHEMA)
    return config
Пример #2
0
def init_config(config_file=configuration.get_user_config(),
                from_config_file=constants.DEFAULT_CONFIG_FILE):
    """
    Initialize default config
    :param config_file: the config file path
    :param from_config_file: the default config file path
    """
    try:
        if not os.path.exists(common_constants.USER_FOLDER):
            os.makedirs(common_constants.USER_FOLDER)

        shutil.copyfile(from_config_file, config_file)
    except Exception as global_exception:
        raise Exception(f"Can't init config file {global_exception}")
Пример #3
0
def migrate_from_previous_config(config):
    logger = logging.get_logger(LOGGER_NAME)
    # migrate tentacles configuration if necessary
    previous_tentacles_config = os.path.join(common_constants.USER_FOLDER,
                                             "tentacles_config")
    previous_tentacles_config_save = os.path.join(common_constants.USER_FOLDER,
                                                  "tentacles_config.back")
    if os.path.isdir(previous_tentacles_config) and \
            not os.path.isdir(tentacles_manager_constants.USER_REFERENCE_TENTACLE_CONFIG_PATH):
        logger.info(
            f"Updating your tentacles configuration located in {previous_tentacles_config} into the new format. "
            f"A save of your previous tentacles config is available in {previous_tentacles_config_save}"
        )
        shutil.copytree(
            previous_tentacles_config,
            tentacles_manager_constants.USER_REFERENCE_TENTACLE_CONFIG_PATH)
        shutil.move(previous_tentacles_config, previous_tentacles_config_save)
        load_default_tentacles_config(
            os.path.join(common_constants.USER_PROFILES_FOLDER,
                         common_constants.DEFAULT_PROFILE))
    # migrate global configuration if necessary
    config_path = configuration.get_user_config()
    previous_config_save_path = f"{config_path}.back"
    logger.info(
        f"Updating your {config_path} into the new format. A save of your previous config is available in "
        f"{previous_config_save_path}")
    # save the current config file in case some data should be kept
    shutil.copyfile(config_path, previous_config_save_path)
    if common_constants.CONFIG_CRYPTO_CURRENCIES in config.config:
        # config migration required
        # add missing exchange enabled config
        for exchange_config in config.config[
                common_constants.CONFIG_EXCHANGES].values():
            exchange_config[common_constants.CONFIG_ENABLED_OPTION] = \
                exchange_config.get(common_constants.CONFIG_ENABLED_OPTION, True)
        for key in ("tentacles-packages", "performance-analyser", "PERF",
                    "SAVE_EVALUATIONS"):
            config.config.pop(key, None)
        config.save()
        return True
    else:
        # real config issue
        return False
Пример #4
0
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)