Esempio n. 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
Esempio n. 2
0
def is_compatible_account(exchange_name: str, api_key, api_sec, api_pass) -> dict:
    to_check_config = copy.deepcopy(interfaces_util.get_edited_config()[commons_constants.CONFIG_EXCHANGES].get(exchange_name, {}))
    if _is_real_exchange_value(api_key):
        to_check_config[commons_constants.CONFIG_EXCHANGE_KEY] = configuration.encrypt(api_key).decode()
    if _is_real_exchange_value(api_sec):
        to_check_config[commons_constants.CONFIG_EXCHANGE_SECRET] = configuration.encrypt(api_sec).decode()
    if _is_real_exchange_value(api_pass):
        to_check_config[commons_constants.CONFIG_EXCHANGE_PASSWORD] = configuration.encrypt(api_pass).decode()
    is_compatible = False
    is_sponsoring = trading_api.is_sponsoring(exchange_name)
    is_configured = False
    authenticator = interfaces_util.get_bot_api().get_community_auth()
    is_supporter = authenticator.supports.is_supporting()
    error = None
    if _is_possible_exchange_config(to_check_config):
        is_configured = True
        is_compatible, error = interfaces_util.run_in_bot_async_executor(
            trading_api.is_compatible_account(
                exchange_name,
                to_check_config,
                interfaces_util.get_edited_tentacles_config()
            )
        )
    return {
        "exchange": exchange_name,
        "compatible": is_compatible,
        "supporter_account": is_supporter,
        "configured": is_configured,
        "supporting": is_sponsoring,
        "error_message": error
    }
Esempio n. 3
0
def get_backtesting_report(source):
    tools = web_interface_root.WebInterface.tools
    if tools[constants.BOT_TOOLS_BACKTESTING]:
        backtesting = tools[constants.BOT_TOOLS_BACKTESTING]
        if tools[constants.BOT_TOOLS_BACKTESTING_SOURCE] == source:
            return interfaces_util.run_in_bot_async_executor(
                octobot_api.get_independent_backtesting_report(backtesting))
    return {}
Esempio n. 4
0
def get_timeframes_list(exchanges):
    timeframes_list = []
    allowed_timeframes = set(tf.value for tf in commons_enums.TimeFrames)
    for exchange in exchanges:
        if exchange not in exchange_symbol_fetch_blacklist:
            timeframes_list += interfaces_util.run_in_bot_async_executor(
                    trading_api.get_exchange_available_time_frames(exchange))
    return [commons_enums.TimeFrames(time_frame)
                for time_frame in list(set(timeframes_list))
                if time_frame in allowed_timeframes]
Esempio n. 5
0
def save_data_file(name, file):
    try:
        output_file = f"{backtesting_constants.BACKTESTING_FILE_PATH}/{name}"
        file.save(output_file)
        message = interfaces_util.run_in_bot_async_executor(_convert_into_octobot_data_file_if_necessary(output_file))
        LOGGER.info(message)
        return True, message
    except Exception as e:
        message = f"Error when saving file: {e}. File can't be saved."
        LOGGER.error(message)
        return False, message
Esempio n. 6
0
def collect_data_file(exchange, symbol):
    success = False
    try:
        result = interfaces_util.run_in_bot_async_executor(
            backtesting_api.collect_exchange_historical_data(exchange,
                                                             interfaces_util.get_bot_api().get_edited_tentacles_config(),
                                                             [symbol]))
        success = True
    except Exception as e:
        result = f"data collector error: {e}"

    if success:
        return success, f"{result} saved"
    else:
        return success, f"Can't collect data for {symbol} on {exchange} ({result})"
Esempio n. 7
0
def get_data_files_with_description():
    files = backtesting_api.get_all_available_data_files()
    return interfaces_util.run_in_bot_async_executor(_retrieve_data_files_with_description(files))
Esempio n. 8
0
def get_current_octobots_stats():
    return interfaces_util.run_in_bot_async_executor(octobot_community.get_current_octobots_stats())