Exemplo n.º 1
0
def data_collector():
    if flask.request.method == 'POST':
        action_type = flask.request.args["action_type"]
        success = False
        reply = "Action failed"
        if action_type == "delete_data_file":
            file = flask.request.get_json()
            success, reply = models.get_delete_data_file(file)
        elif action_type == "start_collector":
            details = flask.request.get_json()
            success, reply = models.collect_data_file(details["exchange"], details["symbol"])
        elif action_type == "import_data_file":
            if flask.request.files:
                file = flask.request.files['file']
                name = werkzeug.utils.secure_filename(flask.request.files['file'].filename)
                success, reply = models.save_data_file(name, file)
                alert = {"success": success, "message": reply}
            else:
                alert = {}
            current_exchange = models.get_current_exchange()

            # here return template to force page reload because of file upload via input form
            return flask.render_template('data_collector.html',
                                         data_files=models.get_data_files_with_description(),
                                         ccxt_exchanges=sorted(models.get_full_exchange_list()),
                                         current_exchange=models.get_current_exchange(),
                                         full_symbol_list=sorted(models.get_symbol_list([current_exchange])),
                                         alert=alert)
        if success:
            return util.get_rest_reply(flask.jsonify(reply))
        else:
            return util.get_rest_reply(reply, 500)

    elif flask.request.method == 'GET':
        origin_page = None
        if flask.request.args:
            action_type_key = "action_type"
            if action_type_key in flask.request.args:
                target = flask.request.args[action_type_key]
                if target == "symbol_list":
                    exchange = flask.request.args.get('exchange')
                    return flask.jsonify(sorted(models.get_symbol_list([exchange])))
            from_key = "from"
            if from_key in flask.request.args:
                origin_page = flask.request.args[from_key]

        current_exchange = models.get_current_exchange()
        return flask.render_template('data_collector.html',
                                     data_files=models.get_data_files_with_description(),
                                     ccxt_exchanges=sorted(models.get_full_exchange_list()),
                                     current_exchange=models.get_current_exchange(),
                                     full_symbol_list=sorted(models.get_symbol_list([current_exchange])),
                                     origin_page=origin_page,
                                     alert={})
Exemplo n.º 2
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))
Exemplo n.º 3
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))