Example #1
0
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}"
Example #2
0
def collect_data_file(exchange,
                      symbols,
                      time_frames=None,
                      start_timestamp=None,
                      end_timestamp=None):
    if not exchange:
        return False, "Please select an exchange."
    if not symbols:
        return False, "Please select a trading pair."
    if web_interface_root.WebInterface.tools[constants.BOT_TOOLS_DATA_COLLECTOR] is None or \
            backtesting_api.is_data_collector_finished(
                web_interface_root.WebInterface.tools[constants.BOT_TOOLS_DATA_COLLECTOR]):
        if time_frames is not None:
            time_frames = time_frames if isinstance(time_frames,
                                                    list) else [time_frames]
            if not any(
                    isinstance(time_frame, commons_enums.TimeFrames)
                    for time_frame in time_frames):
                time_frames = time_frame_manager.parse_time_frames(time_frames)
        interfaces_util.run_in_bot_main_loop(
            _background_collect_exchange_historical_data(
                exchange, symbols, time_frames, start_timestamp,
                end_timestamp))
        return True, f"Historical data collection started."
    else:
        return False, f"Can't collect data for {symbols} on {exchange} (Historical data collector is already running)"
Example #3
0
def user_command():
    request_data = flask.request.get_json()
    interfaces_util.run_in_bot_main_loop(
        services_api.send_user_command(
            interfaces_util.get_bot_api().get_bot_id(),
            request_data["subject"], request_data["action"],
            request_data["data"]))
    return flask.jsonify(request_data)
Example #4
0
def stop_data_collector():
    success = False
    message = "Failed to stop data collector"
    if web_interface_root.WebInterface.tools[
            constants.BOT_TOOLS_DATA_COLLECTOR] is not None:
        success = interfaces_util.run_in_bot_main_loop(
            backtesting_api.stop_data_collector(
                web_interface_root.WebInterface.tools[
                    constants.BOT_TOOLS_DATA_COLLECTOR]))
        message = "Data collector stopped"
        web_interface_root.WebInterface.tools[
            constants.BOT_TOOLS_DATA_COLLECTOR] = None
    return success, message
Example #5
0
def call_tentacle_manager(coro, *args, **kwargs):
    return interfaces_util.run_in_bot_main_loop(coro(*args, **kwargs)) == 0