Example #1
0
def profile():
    selected_profile = flask.request.args.get("select", None)
    if selected_profile is not None and selected_profile != models.get_current_profile(
    ).profile_id:
        models.select_profile(selected_profile)
        current_profile = models.get_current_profile()
        flask.flash(f"Switched to {current_profile.name} profile.", "success")
    else:
        current_profile = models.get_current_profile()
    media_url = flask.url_for("tentacle_media", _external=True)
    display_config = interfaces_util.get_edited_config()

    missing_tentacles = set()
    profiles = models.get_profiles()
    config_exchanges = display_config[commons_constants.CONFIG_EXCHANGES]

    return flask.render_template(
        'profile.html',
        current_profile=current_profile,
        profiles=profiles,
        profiles_activated_tentacles=models.get_profiles_activated_tentacles(
            profiles),
        config_exchanges=config_exchanges,
        config_trading=display_config[commons_constants.CONFIG_TRADING],
        config_trader=display_config[commons_constants.CONFIG_TRADER],
        config_trader_simulator=display_config[
            commons_constants.CONFIG_SIMULATOR],
        config_symbols=models.format_config_symbols(display_config),
        config_reference_market=display_config[
            commons_constants.CONFIG_TRADING][
                commons_constants.CONFIG_TRADER_REFERENCE_MARKET],
        real_trader_activated=interfaces_util.
        has_real_and_or_simulated_traders()[0],
        symbol_list=sorted(
            models.get_symbol_list([
                exchange for exchange in display_config[
                    commons_constants.CONFIG_EXCHANGES]
            ])),
        full_symbol_list=models.get_all_symbols_dict(),
        evaluator_config=models.get_evaluator_detailed_config(
            media_url, missing_tentacles),
        strategy_config=models.get_strategy_config(media_url,
                                                   missing_tentacles),
        evaluator_startup_config=models.
        get_evaluators_tentacles_startup_activation(),
        trading_startup_config=models.get_trading_tentacles_startup_activation(
        ),
        missing_tentacles=missing_tentacles,
        in_backtesting=backtesting_api.is_backtesting_enabled(display_config),
        config_tentacles_by_group=models.
        get_tentacles_activation_desc_by_group(media_url, missing_tentacles),
        exchanges_details=models.get_exchanges_details(config_exchanges))
Example #2
0
def evaluator_config():
    if flask.request.method == 'POST':
        request_data = flask.request.get_json()
        success = True
        response = ""

        if request_data:
            # update evaluator config if required
            if constants.EVALUATOR_CONFIG_KEY in request_data and request_data[
                    constants.EVALUATOR_CONFIG_KEY]:
                success = success and models.update_tentacles_activation_config(
                    request_data[constants.EVALUATOR_CONFIG_KEY])

            response = {
                "evaluator_updated_config":
                request_data[constants.EVALUATOR_CONFIG_KEY]
            }

        if success:
            if request_data.get("restart_after_save", False):
                models.schedule_delayed_command(models.restart_bot)
            return util.get_rest_reply(flask.jsonify(response))
        else:
            return util.get_rest_reply('{"update": "ko"}', 500)
    else:
        media_url = flask.url_for("tentacle_media", _external=True)
        missing_tentacles = set()
        return flask.render_template(
            'advanced_evaluator_config.html',
            evaluator_config=models.get_evaluator_detailed_config(
                media_url, missing_tentacles),
            evaluator_startup_config=models.
            get_evaluators_tentacles_startup_activation(),
            missing_tentacles=missing_tentacles,
            current_profile=models.get_current_profile())
Example #3
0
def config_tentacle():
    if flask.request.method == 'POST':
        tentacle_name = flask.request.args.get("name")
        action = flask.request.args.get("action")
        success = True
        response = ""
        if action == "update":
            request_data = flask.request.get_json()
            success, response = models.update_tentacle_config(
                tentacle_name, request_data)
        elif action == "factory_reset":
            success, response = models.reset_config_to_default(tentacle_name)
        if success:
            return util.get_rest_reply(flask.jsonify(response))
        else:
            return util.get_rest_reply(response, 500)
    else:
        if flask.request.args:
            tentacle_name = flask.request.args.get("name")
            missing_tentacles = set()
            media_url = flask.url_for("tentacle_media", _external=True)
            tentacle_class, tentacle_type, tentacle_desc = models.get_tentacle_from_string(
                tentacle_name, media_url)
            evaluator_config = models.get_evaluator_detailed_config(media_url,
                                                                    missing_tentacles) if tentacle_type == "strategy" and \
                                                                                          tentacle_desc[
                                                                                              models.REQUIREMENTS_KEY] == [
                                                                                              "*"] else None
            strategy_config = models.get_strategy_config(media_url,
                                                         missing_tentacles) if tentacle_type == "trading mode" and \
                                                                               len(tentacle_desc[
                                                                                       models.REQUIREMENTS_KEY]) > 1 else None
            evaluator_startup_config = models.get_evaluators_tentacles_startup_activation() \
                if evaluator_config or strategy_config else None
            tentacle_commands = models.get_tentacle_user_commands(
                tentacle_class)
            return flask.render_template(
                'config_tentacle.html',
                name=tentacle_name,
                tentacle_type=tentacle_type,
                tentacle_class=tentacle_class,
                tentacle_desc=tentacle_desc,
                evaluator_startup_config=evaluator_startup_config,
                strategy_config=strategy_config,
                evaluator_config=evaluator_config,
                activated_trading_mode=models.
                get_config_activated_trading_mode(),
                data_files=models.get_data_files_with_description(),
                missing_tentacles=missing_tentacles,
                user_commands=tentacle_commands,
                current_profile=models.get_current_profile())
        else:
            return flask.render_template('config_tentacle.html')