Example #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={})
Example #2
0
def backtesting():
    if request.method == 'POST':
        action_type = request.args["action_type"]
        success = False
        reply = "Action failed"
        if action_type == "start_backtesting":
            files = request.get_json()
            success, reply = start_backtesting_using_specific_files(files)

        if success:
            return get_rest_reply(jsonify(reply))
        else:
            return get_rest_reply(reply, 500)

    elif request.method == 'GET':
        if request.args:
            target = request.args["update_type"]
            if target == "backtesting_report":
                backtesting_report = get_backtesting_report()
                return jsonify(backtesting_report)
            elif target == "backtesting_status":
                backtesting_status, progress = get_backtesting_status()
                status = {"status": backtesting_status, "progress": progress}
                return jsonify(status)

        else:
            return render_template(
                'backtesting.html',
                data_files=get_data_files_with_description())
Example #3
0
def backtesting():
    if request.method == 'POST':
        action_type = request.args["action_type"]
        success = False
        reply = "Action failed"
        if action_type == "start_backtesting":
            files = request.get_json()
            source = request.args["source"]
            reset_tentacle_config = request.args["reset_tentacle_config"] if "reset_tentacle_config" in request.args \
                else False
            success, reply = start_backtesting_using_specific_files(
                files, source, reset_tentacle_config)

        if success:
            return get_rest_reply(jsonify(reply))
        else:
            return get_rest_reply(reply, 500)

    elif request.method == 'GET':
        if request.args:
            target = request.args["update_type"]
            if target == "backtesting_report":
                source = request.args["source"]
                backtesting_report = get_backtesting_report(source)
                return jsonify(backtesting_report)
            elif target == "backtesting_status":
                backtesting_status, progress = get_backtesting_status()
                status = {"status": backtesting_status, "progress": progress}
                return jsonify(status)

        else:
            return render_template(
                'backtesting.html',
                activated_trading_mode=get_config_activated_trading_mode(),
                data_files=get_data_files_with_description())
Example #4
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')