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

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

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

        current_exchange = get_current_exchange()
        return render_template('data_collector.html',
                               data_files=get_data_files_with_description(),
                               ccxt_exchanges=sorted(get_full_exchange_list()),
                               current_exchange=get_current_exchange(),
                               full_symbol_list=sorted(
                                   get_symbol_list([current_exchange])),
                               origin_page=origin_page,
                               alert={})
コード例 #2
0
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])

            # 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])

            # 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])

            # 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)

            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_exchanges=sorted(get_full_exchange_list(True)),
            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())