Exemple #1
0
def config_tentacle():
    if request.method == 'POST':
        tentacle_name = request.args.get("name")
        action = request.args.get("action")
        success = True
        response = ""
        if action == "update":
            request_data = request.get_json()
            success, response = update_tentacle_config(tentacle_name, request_data)
        elif action == "factory_reset":
            success, response = reset_config_to_default(tentacle_name)
        if success:
            return get_rest_reply(jsonify(response))
        else:
            return get_rest_reply(response, 500)
    else:
        if request.args:
            tentacle_name = request.args.get("name")
            tentacle_class, tentacle_type, tentacle_desc = get_tentacle_from_string(tentacle_name)
            evaluator_config = get_evaluator_detailed_config() if tentacle_type == "strategy" and \
                tentacle_desc[REQUIREMENTS_KEY] == ["*"] else None
            strategy_config = get_strategy_config() if tentacle_type == "trading mode" and \
                len(tentacle_desc[REQUIREMENTS_KEY]) > 1 else None
            evaluator_startup_config = get_evaluator_startup_config() if evaluator_config or strategy_config else None
            return 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=get_config_activated_trading_mode(edited_config=True),
                                   data_files=get_data_files_with_description())
        else:
            return render_template('config_tentacle.html')
def config():
    if request.method == 'POST':
        request_data = request.get_json()
        success = True
        response = ""

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

            # update trading config if required
            if TRADING_CONFIG_KEY in request_data and request_data[
                    TRADING_CONFIG_KEY]:
                success = success and update_trading_config(
                    request_data[TRADING_CONFIG_KEY])
            else:
                request_data[TRADING_CONFIG_KEY] = ""

            # update evaluator config if required
            if EVALUATOR_CONFIG_KEY in request_data and request_data[
                    EVALUATOR_CONFIG_KEY]:
                success = success and update_evaluator_config(
                    request_data[EVALUATOR_CONFIG_KEY])
            else:
                request_data[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 update_global_config(
                    request_data[removed_elements_key], delete=True)
            else:
                request_data[removed_elements_key] = ""

            response = {
                "evaluator_updated_config": request_data[EVALUATOR_CONFIG_KEY],
                "trading_updated_config": request_data[TRADING_CONFIG_KEY],
                "global_updated_config": request_data[GLOBAL_CONFIG_KEY],
                removed_elements_key: request_data[removed_elements_key]
            }

        if success:
            return get_rest_reply(jsonify(response))
        else:
            return get_rest_reply('{"update": "ko"}', 500)
    else:
        display_config = get_edited_config()

        # service lists
        service_list, service_name_list = get_services_list()

        return render_template(
            'config.html',
            config_exchanges=display_config[CONFIG_EXCHANGES],
            config_trading=display_config[CONFIG_TRADING],
            config_trader=display_config[CONFIG_TRADER],
            config_trader_simulator=display_config[CONFIG_SIMULATOR],
            config_notifications=display_config[CONFIG_CATEGORY_NOTIFICATION],
            config_services=display_config[CONFIG_CATEGORY_SERVICES],
            config_symbols=display_config[CONFIG_CRYPTO_CURRENCIES],
            config_reference_market=display_config[CONFIG_TRADING]
            [CONFIG_TRADER_REFERENCE_MARKET],
            ccxt_tested_exchanges=get_tested_exchange_list(),
            ccxt_simulated_tested_exchanges=get_simulated_exchange_list(),
            ccxt_other_exchanges=sorted(get_other_exchange_list()),
            services_list=service_list,
            service_name_list=service_name_list,
            symbol_list=sorted(
                get_symbol_list([
                    exchange for exchange in display_config[CONFIG_EXCHANGES]
                ])),
            full_symbol_list=get_all_symbol_list(),
            strategy_config=get_strategy_config(),
            evaluator_startup_config=get_evaluator_startup_config(),
            trading_startup_config=get_trading_startup_config())