Exemple #1
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))

            logger.info("Loading config files...")
            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:

                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.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)
                    try:
                        main.__init__(config)
                    except NameError as e:
                        logging.error(
                            "{0}, impossible to display GUI".format(e))

                    if starting_args.start:
                        Commands.start_bot(bot, logger)

    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")
        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)
Exemple #2
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)
Exemple #3
0
    else:
        # In those cases load OctoBot
        from octobot import OctoBot

        config[CONFIG_EVALUATOR] = load_config(CONFIG_EVALUATOR_FILE_PATH,
                                               False)

        TelegramApp.enable(config, args.telegram)

        WebService.enable(config, args.web)

        bot = OctoBot(config)

        import interfaces

        interfaces.__init__(bot, config)

        if args.data_collector:
            Commands.data_collector(config)

        # start crypto bot options
        else:
            if args.backtesting:
                import backtesting

                backtesting.__init__(bot)

                config[CONFIG_BACKTESTING][CONFIG_ENABLED_OPTION] = True
                config[CONFIG_CATEGORY_NOTIFICATION][
                    CONFIG_ENABLED_OPTION] = False
Exemple #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)
Exemple #5
0
def start_octobot(starting_args):
    if starting_args.pause_time is not None:
        sleep(starting_args.pause_time)

    fileConfig('config/logging_config.ini')

    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

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

    # Test update
    if starting_args.update:
        Commands.update(logger)
    else:
        Commands.check_bot_update(logger)

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

        # 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)

        else:
            # In those cases load OctoBot
            from octobot import OctoBot

            config[CONFIG_EVALUATOR] = load_config(CONFIG_EVALUATOR_FILE_PATH,
                                                   False)

            TelegramApp.enable(config, starting_args.telegram)

            WebService.enable(config, starting_args.web)

            bot = OctoBot(config)

            import interfaces

            interfaces.__init__(bot, config)

            if starting_args.data_collector:
                Commands.data_collector(config)

            # start crypto bot options
            else:
                if starting_args.backtesting:
                    import backtesting

                    backtesting.__init__(bot)

                    config[CONFIG_BACKTESTING][CONFIG_ENABLED_OPTION] = True
                    config[CONFIG_CATEGORY_NOTIFICATION][
                        CONFIG_ENABLED_OPTION] = False

                    config[CONFIG_TRADER][CONFIG_ENABLED_OPTION] = False
                    config[CONFIG_SIMULATOR][CONFIG_ENABLED_OPTION] = True

                if starting_args.simulate:
                    config[CONFIG_TRADER][CONFIG_ENABLED_OPTION] = False
                    config[CONFIG_SIMULATOR][CONFIG_ENABLED_OPTION] = True

                if starting_args.risk is not None and 0 < starting_args.risk <= 1:
                    config[CONFIG_TRADER][
                        CONFIG_TRADER_RISK] = starting_args.risk

                if starting_args.start:
                    Commands.start_bot(bot, logger)