示例#1
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)
        return flask.render_template(
            'advanced_evaluator_config.html',
            evaluator_config=models.get_evaluator_detailed_config(media_url),
            evaluator_startup_config=models.
            get_evaluators_tentacles_startup_activation())
示例#2
0
def config():
    request_data = flask.request.get_json()
    success = True
    response = ""

    if request_data:

        # update trading config if required
        if constants.TRADING_CONFIG_KEY in request_data and request_data[constants.TRADING_CONFIG_KEY]:
            success = success and models.update_tentacles_activation_config(
                request_data[constants.TRADING_CONFIG_KEY])
        else:
            request_data[constants.TRADING_CONFIG_KEY] = ""

        # update tentacles config if required
        if constants.TENTACLES_CONFIG_KEY in request_data and request_data[constants.TENTACLES_CONFIG_KEY]:
            success = success and models.update_tentacles_activation_config(
                request_data[constants.TENTACLES_CONFIG_KEY])
        else:
            request_data[constants.TENTACLES_CONFIG_KEY] = ""

        # update evaluator config if required
        if constants.EVALUATOR_CONFIG_KEY in request_data and request_data[constants.EVALUATOR_CONFIG_KEY]:
            deactivate_others = False
            if constants.DEACTIVATE_OTHERS in request_data:
                deactivate_others = request_data[constants.DEACTIVATE_OTHERS]
            success = success and models.update_tentacles_activation_config(
                request_data[constants.EVALUATOR_CONFIG_KEY],
                deactivate_others)
        else:
            request_data[constants.EVALUATOR_CONFIG_KEY] = ""

        # remove elements from global config if any to remove
        removed_elements_key = "removed_elements"
        if removed_elements_key in request_data and request_data[removed_elements_key]:
            success = success and models.update_global_config(request_data[removed_elements_key], delete=True)
        else:
            request_data[removed_elements_key] = ""

        # update global config if required
        if constants.GLOBAL_CONFIG_KEY in request_data and request_data[constants.GLOBAL_CONFIG_KEY]:
            success = models.update_global_config(request_data[constants.GLOBAL_CONFIG_KEY])
        else:
            request_data[constants.GLOBAL_CONFIG_KEY] = ""

        response = {
            "evaluator_updated_config": request_data[constants.EVALUATOR_CONFIG_KEY],
            "trading_updated_config": request_data[constants.TRADING_CONFIG_KEY],
            "tentacle_updated_config": request_data[constants.TENTACLES_CONFIG_KEY],
            "global_updated_config": request_data[constants.GLOBAL_CONFIG_KEY],
            removed_elements_key: request_data[removed_elements_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)
示例#3
0
def commands(cmd=None):
    if cmd == "restart":
        models.restart_bot()
        return flask.jsonify("Success")

    elif cmd == "stop":
        models.stop_bot()
        return flask.jsonify("Success")

    elif cmd == "update":
        models.schedule_delayed_command(models.update_bot())
        return flask.jsonify("Update started")

    else:
        raise RuntimeError("Unknown command")
def send_and_remove_file(file_path, attachment_filename):
    try:
        return flask.send_file(file_path,
                               as_attachment=True,
                               attachment_filename=attachment_filename,
                               cache_timeout=0)
    finally:
        # cleanup temp_file
        def remove_file(file_path):
            try:
                os.remove(file_path)
            except Exception:
                pass

        models.schedule_delayed_command(remove_file, file_path, delay=2)
示例#5
0
def profiles_management(action):
    if action == "update":
        data = flask.request.get_json()
        models.update_profile(flask.request.get_json()["id"], data)
        return util.get_rest_reply(flask.jsonify(data))
    if action == "duplicate":
        profile_id = flask.request.args.get("profile_id")
        models.duplicate_and_select_profile(profile_id)
        flask.flash(f"New profile successfully created and selected.", "success")
        return util.get_rest_reply(flask.jsonify("Profile created"))
    if action == "remove":
        data = flask.request.get_json()
        to_remove_id = data["id"]
        removed_profile, err = models.remove_profile(to_remove_id)
        if err is not None:
            return util.get_rest_reply(flask.jsonify(str(err)), code=400)
        flask.flash(f"{removed_profile.name} profile removed.", "success")
        return util.get_rest_reply(flask.jsonify("Profile created"))
    if action == "import":
        file = flask.request.files['file']
        name = werkzeug.utils.secure_filename(flask.request.files['file'].filename)
        models.import_profile(file, name)
        flask.flash(f"{name} profile successfully imported.", "success")
        return flask.redirect(flask.url_for('profile'))
    if action == "export":
        profile_id = flask.request.args.get("profile_id")
        temp_file = os.path.abspath("profile")
        file_path = models.export_profile(profile_id, temp_file)
        try:
            return flask.send_file(file_path, as_attachment=True, attachment_filename="profile.zip", cache_timeout=0)
        finally:
            # cleanup temp_file
            def remove_file(file_path):
                try:
                    os.remove(file_path)
                except Exception:
                    pass
            models.schedule_delayed_command(remove_file, file_path, delay=2)
示例#6
0
def config():
    if flask.request.method == 'POST':
        request_data = flask.request.get_json()
        success = True
        response = ""

        if request_data:

            # update trading config if required
            if constants.TRADING_CONFIG_KEY in request_data and request_data[
                    constants.TRADING_CONFIG_KEY]:
                success = success and models.update_tentacles_activation_config(
                    request_data[constants.TRADING_CONFIG_KEY])
            else:
                request_data[constants.TRADING_CONFIG_KEY] = ""

            # update tentacles config if required
            if constants.TENTACLES_CONFIG_KEY in request_data and request_data[
                    constants.TENTACLES_CONFIG_KEY]:
                success = success and models.update_tentacles_activation_config(
                    request_data[constants.TENTACLES_CONFIG_KEY])
            else:
                request_data[constants.TENTACLES_CONFIG_KEY] = ""

            # update evaluator config if required
            if constants.EVALUATOR_CONFIG_KEY in request_data and request_data[
                    constants.EVALUATOR_CONFIG_KEY]:
                deactivate_others = False
                if constants.DEACTIVATE_OTHERS in request_data:
                    deactivate_others = request_data[
                        constants.DEACTIVATE_OTHERS]
                success = success and models.update_tentacles_activation_config(
                    request_data[constants.EVALUATOR_CONFIG_KEY],
                    deactivate_others)
            else:
                request_data[constants.EVALUATOR_CONFIG_KEY] = ""

            # remove elements from global config if any to remove
            removed_elements_key = "removed_elements"
            if removed_elements_key in request_data and request_data[
                    removed_elements_key]:
                success = success and models.update_global_config(
                    request_data[removed_elements_key], delete=True)
            else:
                request_data[removed_elements_key] = ""

            # update global config if required
            if constants.GLOBAL_CONFIG_KEY in request_data and request_data[
                    constants.GLOBAL_CONFIG_KEY]:
                success = models.update_global_config(
                    request_data[constants.GLOBAL_CONFIG_KEY])
            else:
                request_data[constants.GLOBAL_CONFIG_KEY] = ""

            response = {
                "evaluator_updated_config":
                request_data[constants.EVALUATOR_CONFIG_KEY],
                "trading_updated_config":
                request_data[constants.TRADING_CONFIG_KEY],
                "tentacle_updated_config":
                request_data[constants.TENTACLES_CONFIG_KEY],
                "global_updated_config":
                request_data[constants.GLOBAL_CONFIG_KEY],
                removed_elements_key:
                request_data[removed_elements_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)
        display_config = interfaces_util.get_edited_config()

        # service lists
        service_list = models.get_services_list()
        notifiers_list = models.get_notifiers_list()

        return flask.render_template(
            'config.html',
            config_exchanges=display_config[
                commons_constants.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_notifications=display_config[
                services_constants.CONFIG_CATEGORY_NOTIFICATION],
            config_services=display_config[
                services_constants.CONFIG_CATEGORY_SERVICES],
            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],
            ccxt_tested_exchanges=models.get_tested_exchange_list(),
            ccxt_simulated_tested_exchanges=models.get_simulated_exchange_list(
            ),
            ccxt_other_exchanges=sorted(models.get_other_exchange_list()),
            services_list=service_list,
            notifiers_list=notifiers_list,
            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(),
            strategy_config=models.get_strategy_config(media_url),
            evaluator_startup_config=models.
            get_evaluators_tentacles_startup_activation(),
            trading_startup_config=models.
            get_trading_tentacles_startup_activation(),
            in_backtesting=backtesting_api.is_backtesting_enabled(
                display_config),
            config_tentacles_by_group=models.
            get_tentacles_activation_desc_by_group(media_url))