def install_on_development(config, module_dev):
    # is not on development
    if module_dev is None or not module_dev:
        return True

    # is on development
    if module_dev and ConfigManager.is_in_dev_mode(config):
        return True

    return False
 async def eval(self) -> None:
     try:
         self.ensure_eval_note_is_not_expired()
         await self.eval_impl()
     except Exception as e:
         if ConfigManager.is_in_dev_mode(self.config):
             raise e
         else:
             self.logger.error("Exception in eval_impl(): " + str(e))
     finally:
         if self.eval_note == "nan":
             self.eval_note = START_PENDING_EVAL_NOTE
             self.logger.warning(str(self.symbol) + " evaluator returned 'nan' as eval_note, ignoring this value.")
Esempio n. 3
0
def start_octobot(starting_args):
    try:
        fileConfig(LOGGING_CONFIG_FILE)
    except KeyError:
        print("Error when loading logging config file, it might be missing or is corrupted. File is: " +
              LOGGING_CONFIG_FILE)

    logger = logging.getLogger("OctoBot Launcher")

    # Force new log file creation not to log at the previous one's end.
    try:
        logger.parent.handlers[1].doRollover()
    except IndexError:
        print("Logfile rotation disabled: error when handling logging config.")

    sys.excepthook = _log_uncaught_exceptions

    try:
        if starting_args.version:
            print(LONG_VERSION)
        else:
            # Version
            logger.info("Version : {0}".format(LONG_VERSION))

            _check_public_announcements(logger)

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

            # configuration loading
            config = load_config(error=False, fill_missing_fields=True)

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

            if config is None:
                raise ConfigError

            # Set Tentacle package manager current working directory
            TentaclePathHandler.set_tentacle_parent_directory(PROJECT_ROOT_DIR)

            # Handle utility methods before bot initializing if possible
            if starting_args.packager:
                Commands.package_manager(config, starting_args.packager)

            elif starting_args.creator:
                Commands.tentacle_creator(config, starting_args.creator)

            elif starting_args.encrypter:
                Commands.exchange_keys_encrypter()

            else:
                if not tentacles_arch_exists():
                    logger.info("No tentacles found. Installing default tentacles ...")
                    Commands.package_manager(config, ["install", "all"], force=True)

                ConfigManager.reload_tentacle_config(config)

                if starting_args.data_collector:
                    Commands.data_collector(config)

                elif starting_args.strategy_optimizer:
                    Commands.start_strategy_optimizer(config, starting_args.strategy_optimizer)

                else:

                    # In those cases load OctoBot
                    from core.octobot import OctoBot
                    from interfaces.bots.telegram.bot import TelegramApp
                    from services import WebService

                    TelegramApp.enable(config, not starting_args.no_telegram)
                    WebService.enable(config, not starting_args.no_web)

                    update_config_with_args(starting_args, config)

                    reset_trading_history = starting_args.reset_trading_history

                    bot = OctoBot(config, reset_trading_history=reset_trading_history)

                    _log_terms_if_unaccepted(config, logger)

                    import interfaces
                    interfaces.__init__(bot, config)

                    if not starting_args.no_open_web and not starting_args.no_web:
                        Thread(target=_auto_open_web, args=(config, bot)).start()

                    # set debug_mode = True to activate asyncio debug mode
                    debug_mode = ConfigManager.is_in_dev_mode(config) or FORCE_ASYNCIO_DEBUG_OPTION
                    asyncio.run(Commands.start_bot(bot, logger), debug=debug_mode)
    except ConfigError:
        logger.error("OctoBot can't start without " + CONFIG_FILE + " configuration file." + "\nYou can use " +
                     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 -p install all")
        else:
            logger.exception(e)
        os._exit(-1)

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

    except ConfigTradingError:
        logger.error("OctoBot can't start without a valid " + CONFIG_TRADING_FILE_PATH
                     + " configuration file.\nThis file is generated on tentacle "
                       "installation using the following command:\nstart.py -p install all")
        os._exit(-1)
Esempio n. 4
0
def start_octobot(starting_args):
    fileConfig(LOGGING_CONFIG_FILE)

    logger = logging.getLogger("OctoBot Launcher")

    # Force new log file creation not to log at the previous one's end.
    logger.parent.handlers[1].doRollover()

    sys.excepthook = _log_uncaught_exceptions

    try:
        if starting_args.version:
            print(LONG_VERSION)
        else:
            # Version
            logger.info("Version : {0}".format(LONG_VERSION))

            _check_public_announcements(logger)

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

            # configuration loading
            config = load_config(error=False)

            if config is None and is_config_empty_or_missing():
                logger.info("No configuration found creating default...")
                init_config()
                config = load_config(error=False)

            if config is None:
                raise ConfigError

            # Handle utility methods before bot initializing if possible
            if starting_args.packager:
                Commands.package_manager(config, starting_args.packager)

            elif starting_args.creator:
                Commands.tentacle_creator(config, starting_args.creator)

            elif starting_args.encrypter:
                Commands.exchange_keys_encrypter()

            else:
                if not tentacles_arch_exists():
                    logger.info(
                        "No tentacles found. Installing default tentacles ...")
                    Commands.package_manager(config, ["install", "all"],
                                             force=True)

                config[CONFIG_EVALUATOR] = load_config(
                    CONFIG_EVALUATOR_FILE_PATH, False)
                if config[CONFIG_EVALUATOR] is None:
                    raise ConfigEvaluatorError

                config[CONFIG_TRADING_TENTACLES] = load_config(
                    CONFIG_TRADING_FILE_PATH, False)
                if config[CONFIG_TRADING_TENTACLES] is None:
                    raise ConfigTradingError

                if starting_args.data_collector:
                    Commands.data_collector(config)

                elif starting_args.strategy_optimizer:
                    Commands.start_strategy_optimizer(
                        config, starting_args.strategy_optimizer)

                else:

                    # In those cases load OctoBot
                    from octobot import OctoBot
                    from interfaces.bots.telegram.bot import TelegramApp
                    from services import WebService

                    TelegramApp.enable(config, starting_args.telegram)
                    WebService.enable(config, not starting_args.no_web)

                    update_config_with_args(starting_args, config)

                    bot = OctoBot(config)

                    import interfaces
                    interfaces.__init__(bot, config)

                    if not starting_args.no_open_web and not starting_args.no_web:
                        Thread(target=_auto_open_web,
                               args=(config, bot)).start()

                    # set debug_mode = True to activate asyncio debug mode
                    debug_mode = ConfigManager.is_in_dev_mode(
                        config) or FORCE_ASYNCIO_DEBUG_OPTION
                    asyncio.run(Commands.start_bot(bot, logger),
                                debug=debug_mode)
    except ConfigError:
        logger.error("OctoBot can't start without " + CONFIG_FILE +
                     " configuration file.")
        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 -p install all")
        else:
            logger.exception(e)
        os._exit(-1)

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

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