Exemplo n.º 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}"
Exemplo n.º 2
0
def start_strategy_optimizer(config, commands):
    tentacles_setup_config = tentacles_manager_api.get_tentacles_setup_config()
    optimizer = strategy_optimizer_api.create_strategy_optimizer(
        config, tentacles_setup_config, commands[0])
    if strategy_optimizer_api.get_optimizer_is_properly_initialized(optimizer):
        strategy_optimizer_api.find_optimal_configuration(optimizer)
        strategy_optimizer_api.print_optimizer_report(optimizer)
Exemplo n.º 3
0
async def create_test_exchange_manager(
        config: object,
        exchange_name: str,
        is_spot_only: bool = True,
        is_margin: bool = False,
        is_future: bool = False,
        rest_only: bool = False,
        is_real: bool = True,
        is_sandboxed: bool = False) -> exchanges.ExchangeManager:
    builder = exchanges.create_exchange_builder_instance(config, exchange_name)
    builder.disable_trading_mode()
    builder.use_tentacles_setup_config(
        tentacles_manager_api.get_tentacles_setup_config())
    if is_spot_only:
        builder.is_spot_only()
    if is_margin:
        builder.is_margin()
    if is_future:
        builder.is_future()
    if rest_only:
        builder.is_rest_only()
    if is_sandboxed:
        builder.is_sandboxed(is_sandboxed)
    if is_real:
        builder.is_real()
    else:
        builder.is_simulated()
    await builder.build()
    return builder.exchange_manager
Exemplo n.º 4
0
    async def create(self):
        # initialize tentacle configuration
        self.octobot.tentacles_setup_config = tentacles_manager_api.get_tentacles_setup_config(
        )

        # create OctoBot channel
        await self.octobot.global_consumer.initialize()
Exemplo n.º 5
0
async def _test_evaluators_creation(evaluator_parent_class, fixture_matrix_id,
                                    expected_evaluators):
    tentacles_setup_config = tentacles_api.get_tentacles_setup_config()

    # activate all evaluators in tentacle config
    for tentacle_type_key, tentacle_type_value in tentacles_setup_config.tentacles_activation.items(
    ):
        for tentacle_name in tentacle_type_value:
            tentacles_setup_config.tentacles_activation[tentacle_type_key][
                tentacle_name] = True

    # mock start method to prevent side effects (octobot-trading imports, etc)
    with mock.patch.object(evaluator_parent_class, "start", mock.AsyncMock()):
        created_evaluators = await evaluators.create_evaluators(
            evaluator_parent_class=evaluator_parent_class,
            tentacles_setup_config=tentacles_setup_config,
            matrix_id=fixture_matrix_id,
            exchange_name=exchange_name,
            bot_id=bot_id,
            crypto_currency_name_by_crypto_currencies=
            crypto_currency_name_by_crypto_currencies,
            symbols_by_crypto_currency_tickers=
            symbols_by_crypto_currency_tickers,
            symbols=symbols,
            time_frames=time_frames)
    assert created_evaluators
    assert all([
        evaluator.__class__ in expected_evaluators
        for evaluator in created_evaluators
    ])
Exemplo n.º 6
0
    async def create(self):
        # initialize tentacle configuration
        tentacles_config_path = self.octobot.get_startup_config(constants.CONFIG_KEY, dict_only=False).\
            get_tentacles_config_path()
        self.octobot.tentacles_setup_config = tentacles_manager_api.get_tentacles_setup_config(tentacles_config_path)

        # create OctoBot channel
        await self.octobot.global_consumer.initialize()
async def test_create_all_type_evaluators(evaluators_and_matrix_channels):
    tentacles_setup_config = tentacles_api.get_tentacles_setup_config()
    created_evaluators = await evaluators.create_all_type_evaluators(tentacles_setup_config,
                                                                     matrix_id=evaluators_and_matrix_channels,
                                                                     exchange_name=exchange_name,
                                                                     bot_id=bot_id,
                                                                     symbols_by_crypto_currencies=symbols_by_crypto_currencies,
                                                                     symbols=symbols,
                                                                     time_frames=time_frames)

    assert not created_evaluators  # Trading package is not installed
Exemplo n.º 8
0
def get_profiles_activated_tentacles(profiles_list):
    tentacles_by_profile_id = {}
    for profile in profiles_list.values():
        try:
            tentacles_by_profile_id[profile.profile_id] = tentacles_manager_api.get_activated_tentacles(
                tentacles_manager_api.get_tentacles_setup_config(profile.get_tentacles_config_path())
            )
        except Exception:
            # do not raise here to prevent avoid config display
            pass
    return tentacles_by_profile_id
Exemplo n.º 9
0
def _load_or_create_tentacles(config, logger):
    # add tentacles folder to Python path
    sys.path.append(os.path.realpath(os.getcwd()))

    # when tentacles folder already exists
    if os.path.isfile(tentacles_manager_constants.
                      USER_REFERENCE_TENTACLE_CONFIG_FILE_PATH):
        config.load_profiles_if_possible_and_necessary()
        tentacles_setup_config = tentacles_manager_api.get_tentacles_setup_config(
            config.get_tentacles_config_path())
        commands.run_update_or_repair_tentacles_if_necessary(
            config, tentacles_setup_config)
    else:
        # when no tentacles folder has been found
        logger.info(
            "OctoBot tentacles can't be found. Installing default tentacles ..."
        )
        commands.run_tentacles_install_or_update(config)
        config.load_profiles_if_possible_and_necessary()
Exemplo n.º 10
0
async def create_test_exchange_manager(
        config: object,
        exchange_name: str,
        is_spot_only: bool = True,
        is_margin: bool = False,
        is_future: bool = False,
        rest_only: bool = False,
        is_real: bool = True,
        is_sandboxed: bool = False,
        ignore_exchange_config: bool = True) -> exchanges.ExchangeManager:
    if ignore_exchange_config:
        # enable exchange name in config
        config[commons_constants.CONFIG_EXCHANGES][exchange_name] = {
            commons_constants.CONFIG_ENABLED_OPTION: True
        }

    builder = exchanges.create_exchange_builder_instance(config, exchange_name)
    builder.disable_trading_mode()
    builder.use_tentacles_setup_config(
        tentacles_manager_api.get_tentacles_setup_config())
    if is_spot_only:
        builder.is_spot_only()
    if is_margin:
        builder.is_margin()
    if is_future:
        builder.is_future()
    if rest_only:
        builder.is_rest_only()
    if is_sandboxed:
        builder.is_sandboxed(is_sandboxed)
    if is_real:
        builder.is_real()
    else:
        builder.is_simulated()
    await builder.build()
    return builder.exchange_manager
Exemplo n.º 11
0
def _update_edited_tentacles_config(config):
    updated_tentacles_config = tentacles_manager_api.get_tentacles_setup_config(
        config.get_tentacles_config_path())
    interfaces_util.set_edited_tentacles_config(updated_tentacles_config)