Пример #1
0
def config_health_check(config: configuration.Configuration,
                        in_backtesting: bool) -> configuration.Configuration:
    logger = logging.get_logger(LOGGER_NAME)
    # 1 ensure api key encryption
    should_replace_config = False
    if common_constants.CONFIG_EXCHANGES in config.config:
        for exchange, exchange_config in config.config[
                common_constants.CONFIG_EXCHANGES].items():
            for key in common_constants.CONFIG_EXCHANGE_ENCRYPTED_VALUES:
                try:
                    if not configuration.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.config)
        if trader_enabled:
            simulator_enabled = trading_api.is_trader_simulator_enabled_in_config(
                config.config)
            if simulator_enabled:
                logger.error(
                    f"Impossible to activate a trader simulator additionally to a "
                    f"real trader, simulator deactivated.")
                config.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.config[common_constants.CONFIG_SIMULATOR][
            common_constants.CONFIG_ENABLED_OPTION] = True
        config.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.config) or
            trading_api.is_trader_simulator_enabled_in_config(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.save()
            return config
        except Exception as e:
            logger.error(f"Save of the health checked config failed : {e}, "
                         f"will use the initial config")
            config.read(should_raise=False, fill_missing_fields=True)
            return config
Пример #2
0
def _log_terms_if_unaccepted(config: configuration.Configuration, logger):
    if not config.accepted_terms():
        logger.info("*** Disclaimer ***")
        for line in disclaimer.DISCLAIMER:
            logger.info(line)
        logger.info("... Disclaimer ...")
    else:
        logger.info("Disclaimer accepted by user.")
Пример #3
0
 def should_register_bot(config: configuration.Configuration):
     try:
         config.get_metrics_id()
         return True
     except KeyError:
         return False