Пример #1
0
async def run_independent_backtesting(data_files,
                                      timeout=10,
                                      use_loggers=True,
                                      run_on_common_part_only=True):
    independent_backtesting = None
    try:
        config_to_use = load_test_config()
        if use_loggers:
            init_logger()
        independent_backtesting = create_independent_backtesting(
            config_to_use,
            load_test_tentacles_config(),
            data_files,
            "",
            run_on_common_part_only=run_on_common_part_only)
        await initialize_and_run_independent_backtesting(
            independent_backtesting, log_errors=False)
        await independent_backtesting.join_backtesting_updater(timeout)
        return independent_backtesting
    except MissingTimeFrame:
        # ignore this exception: is due to missing of the only required time frame
        return independent_backtesting
    except asyncio.TimeoutError as e:
        get_logger().exception(
            e, True,
            f"Timeout after waiting for backtesting for {timeout} seconds.")
        # stop backtesting to prevent zombie tasks
        await stop_independent_backtesting(independent_backtesting)
        raise
    except Exception as e:
        get_logger().exception(e, True, str(e))
        # stop backtesting to prevent zombie tasks
        await stop_independent_backtesting(independent_backtesting)
        raise
Пример #2
0
def call_tentacles_manager(command_args):
    octobot_logger.init_logger()
    tentacles_urls = [
        configuration_manager.get_default_tentacles_url(),
        # tentacles_manager_api.get_compiled_tentacles_url(
        #     constants.DEFAULT_COMPILED_TENTACLES_URL,
        #     constants.TENTACLES_REQUIRED_VERSION
        # )
    ]
    sys.exit(tentacles_manager_cli.handle_tentacles_manager_command(command_args,
                                                                    tentacles_urls=tentacles_urls,
                                                                    bot_install_dir=os.getcwd()))
Пример #3
0
def call_tentacles_manager(command_args):
    octobot_logger.init_logger()
    tentacles_urls = [
        constants.DEFAULT_TENTACLES_URL,
        # tentacles_manager_api.get_compiled_tentacles_url(
        #     constants.DEFAULT_COMPILED_TENTACLES_URL,
        #     constants.TENTACLES_REQUIRED_VERSION
        # )
    ]
    sys.exit(
        tentacles_manager_cli.handle_tentacles_manager_command(
            command_args,
            tentacles_urls=tentacles_urls,
            bot_install_dir=constants.OCTOBOT_FOLDER))
Пример #4
0
async def test_run_bot():
    # avoid web interface in this test
    WebInterface.enabled = False
    bot = OctoBot(load_test_config(dict_only=False), ignore_config=True)
    bot.task_manager.init_async_loop()
    await start_bot(bot, init_logger())
    await asyncio.sleep(10)
    await stop_bot(bot)
Пример #5
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)
Пример #6
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
        _log_environment(logger)

        # _check_public_announcements(logger)

        # load configuration
        config = _create_startup_config(logger)

        # check config loading
        if not config.is_loaded():
            raise errors.ConfigError

        # Handle utility methods before bot initializing if possible
        if args.encrypter:
            commands.exchange_keys_encrypter()
            return

        # add args to config
        update_config_with_args(args, config, logger)

        # show terms
        _log_terms_if_unaccepted(config, logger)

        # tries to load, install or repair tentacles
        _load_or_create_tentacles(config, logger)

        # Can now perform config health check (some checks require a loaded profile)
        configuration_manager.config_health_check(config, args.backtesting)

        # Keep track of errors if any
        octobot_community.register_error_uploader(
            constants.ERRORS_POST_ENDPOINT, config)

        # create OctoBot instance
        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)

        # set global bot instance
        octobot.set_bot(bot)

        # Clear community cache
        bot.community_auth.clear_cache()

        if args.identifier:
            # set community identifier
            bot.community_auth.identifier = args.identifier[0]

        if args.update:
            return commands.update_bot(bot.octobot_api)

        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."
        )
        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)