Exemple #1
0
def start_optimizer(strategy, time_frames, evaluators, risks):
    try:
        tools = web_interface_root.WebInterface.tools
        optimizer = tools[constants.BOT_TOOLS_STRATEGY_OPTIMIZER]
        if optimizer is not None and octobot_api.is_optimizer_computing(
                optimizer):
            return False, "Optimizer already running"
        independent_backtesting = tools[constants.BOT_TOOLS_BACKTESTING]
        if independent_backtesting and octobot_api.is_independent_backtesting_in_progress(
                independent_backtesting):
            return False, "A backtesting is already running"
        else:
            formatted_time_frames = time_frame_manager.parse_time_frames(
                time_frames)
            float_risks = [float(risk) for risk in risks]
            temp_independent_backtesting = octobot_api.create_independent_backtesting(
                interfaces_util.get_global_config(), None, [])
            optimizer_config = interfaces_util.run_in_bot_async_executor(
                octobot_api.initialize_independent_backtesting_config(
                    temp_independent_backtesting))
            optimizer = octobot_api.create_strategy_optimizer(
                optimizer_config,
                interfaces_util.get_bot_api().get_edited_tentacles_config(),
                strategy)
            tools[constants.BOT_TOOLS_STRATEGY_OPTIMIZER] = optimizer
            thread = threading.Thread(
                target=octobot_api.find_optimal_configuration,
                args=(optimizer, evaluators, formatted_time_frames,
                      float_risks),
                name=f"{optimizer.get_name()}-WebInterface-runner")
            thread.start()
            return True, "Optimizer started"
    except Exception as e:
        LOGGER.exception(e, True, f"Error when starting optimizer: {e}")
        raise e
def start_backtesting_using_specific_files(files, source, reset_tentacle_config=False, run_on_common_part_only=True):
    try:
        tools = web_interface_root.WebInterface.tools
        previous_independent_backtesting = tools[constants.BOT_TOOLS_BACKTESTING]
        if tools[constants.BOT_TOOLS_STRATEGY_OPTIMIZER] and octobot_api.is_optimizer_in_progress(
                tools[constants.BOT_TOOLS_STRATEGY_OPTIMIZER]):
            return False, "Optimizer already running"
        elif previous_independent_backtesting and \
                octobot_api.is_independent_backtesting_in_progress(previous_independent_backtesting):
            return False, "A backtesting is already running"
        else:
            if previous_independent_backtesting:
                interfaces_util.run_in_bot_main_loop(
                    octobot_api.stop_independent_backtesting(previous_independent_backtesting))
            if reset_tentacle_config:
                tentacles_config = interfaces_util.get_edited_config(dict_only=False).get_tentacles_config_path()
                tentacles_setup_config = tentacles_manager_api.get_tentacles_setup_config(tentacles_config)
            else:
                tentacles_setup_config = interfaces_util.get_bot_api().get_edited_tentacles_config()
            config = interfaces_util.get_global_config()
            independent_backtesting = octobot_api.create_independent_backtesting(config,
                                                                                 tentacles_setup_config,
                                                                                 files,
                                                                                 run_on_common_part_only=run_on_common_part_only)
            interfaces_util.run_in_bot_main_loop(
                octobot_api.initialize_and_run_independent_backtesting(independent_backtesting), blocking=False)
            tools[constants.BOT_TOOLS_BACKTESTING] = independent_backtesting
            tools[constants.BOT_TOOLS_BACKTESTING_SOURCE] = source
            return True, "Backtesting started"
    except Exception as e:
        LOGGER.exception(e, False)
        return False, f"Error when starting backtesting: {e}"
def get_backtesting_status():
    if web_interface_root.WebInterface.tools[constants.BOT_TOOLS_BACKTESTING] is not None:
        independent_backtesting = web_interface_root.WebInterface.tools[constants.BOT_TOOLS_BACKTESTING]
        if octobot_api.is_independent_backtesting_in_progress(independent_backtesting):
            return "computing", octobot_api.get_independent_backtesting_progress(independent_backtesting) * 100
        if octobot_api.is_independent_backtesting_finished(independent_backtesting) or \
                octobot_api.is_independent_backtesting_stopped(independent_backtesting):
            return "finished", 100
        return "starting", 0
    return "not started", 0