コード例 #1
0
 def get_specific_config(cls, raise_exception=True) -> dict:
     try:
         return load_config(config_file=cls.get_config_file_name())
     except Exception as e:
         if raise_exception:
             raise e
     return {}
コード例 #2
0
 def load_config(self):
     config_file = self.get_config_file_name()
     # try with this class name
     if os.path.isfile(config_file):
         self.specific_config = load_config(config_file)
     else:
         # if it's not possible, try with any super-class' config file
         for super_class in self.get_parent_evaluator_classes(
                 SocialEvaluator):
             super_class_config_file = super_class.get_config_file_name()
             if os.path.isfile(super_class_config_file):
                 self.specific_config = load_config(super_class_config_file)
                 return
     # set default config if nothing found
     if not self.specific_config:
         self.set_default_config()
コード例 #3
0
def check_config(config_file):
    try:
        valid, e = validate_config_file(load_config(config_file=config_file))
        if not valid:
            raise e
    except Exception as e:
        raise e
コード例 #4
0
    def load_config(self) -> None:
        config_file = self.get_config_file_name()
        # try with this class name
        if os.path.isfile(config_file):
            self.trading_config = load_config(config_file)

        # set default config if nothing found
        if not self.trading_config:
            self.set_default_config()
コード例 #5
0
 def load_config(self):
     config_file = self.get_config_file_name()
     if os.path.isfile(config_file):
         self.set_default_config()
         self.specific_config = {
             **self.specific_config,
             **load_config(config_file)
         }
     else:
         self.set_default_config()
コード例 #6
0
def config_health_check(config, in_backtesting):
    logger = logging.get_logger(LOGGER_NAME)
    # 1 ensure api key encryption
    should_replace_config = False
    if common_constants.CONFIG_EXCHANGES in config:
        for exchange, exchange_config in config[
                common_constants.CONFIG_EXCHANGES].items():
            for key in common_constants.CONFIG_EXCHANGE_ENCRYPTED_VALUES:
                try:
                    if not config_manager._handle_encrypted_value(
                            key, exchange_config, verbose=True):
                        should_replace_config = True
                except Exception as e:
                    logger.exception(
                        e, True,
                        f"Exception when checking exchange config encryption: {e}"
                    )

    # 2 ensure single trader activated
    try:
        trader_enabled = trading_api.is_trader_enabled_in_config(config)
        if trader_enabled:
            simulator_enabled = trading_api.is_trader_simulator_enabled_in_config(
                config)
            if simulator_enabled:
                logger.error(
                    f"Impossible to activate a trader simulator additionally to a "
                    f"real trader, simulator deactivated.")
                config[common_constants.CONFIG_SIMULATOR][
                    common_constants.CONFIG_ENABLED_OPTION] = False
                should_replace_config = True
    except KeyError as e:
        logger.exception(
            e, True, f"KeyError when checking traders activation: {e}. "
            f"Activating trader simulator.")
        config[common_constants.CONFIG_SIMULATOR][
            common_constants.CONFIG_ENABLED_OPTION] = True
        config[common_constants.CONFIG_TRADER][
            common_constants.CONFIG_ENABLED_OPTION] = False
        should_replace_config = True

    # 3 inform about configuration issues
    if not (in_backtesting or trading_api.is_trader_enabled_in_config(config)
            or trading_api.is_trader_simulator_enabled_in_config(config)):
        logger.error(
            f"Real trader and trader simulator are deactivated in configuration. This will prevent OctoBot "
            f"from creating any new order.")

    # 4 save fixed config if necessary
    if should_replace_config:
        try:
            config_manager.save_config(
                config.get_user_config(),
                config,
                common_constants.TEMP_RESTORE_CONFIG_FILE,
                common_constants.CONFIG_FILE_SCHEMA,
                json_data=config_manager.dump_json(config))
            return config
        except Exception as e:
            logger.error(f"Save of the health checked config failed : {e}, "
                         f"will use the initial config")
            return config.load_config(error=False, fill_missing_fields=True)
コード例 #7
0
ファイル: cli.py プロジェクト: wdcpclover/OctoBot
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 = common_config.load_config(error=False,
                                           fill_missing_fields=True)

        if config is None and common_config.is_config_empty_or_missing():
            logger.info("No configuration found creating default...")
            configuration_manager.init_config()
            config = common_config.load_config(error=False)
        else:
            is_valid, e = config_manager.validate_config_file(
                config=config, schema_file=constants.CONFIG_FILE_SCHEMA)
            if not is_valid:
                logger.error(
                    "OctoBot can't repair your config.json file: invalid format: "
                    + str(e))
                raise errors.ConfigError
            configuration_manager.config_health_check(config, args.backtesting)

        if config is None:
            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)
        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]

        _log_terms_if_unaccepted(config, logger)

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

        if not 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 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 " +
                     common_constants.CONFIG_FILE + " configuration file." +
                     "\nYou can use " + constants.DEFAULT_CONFIG_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)
コード例 #8
0
def load_test_config():
    config = load_config(get_test_config())
    init_config_time_frame_for_tests(config)
    return config