Example #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={})
Example #2
0
def backtesting():
    if flask.request.method == 'POST':
        action_type = flask.request.args["action_type"]
        success = False
        reply = "Action failed"
        if action_type == "start_backtesting":
            files = flask.request.get_json()
            source = flask.request.args["source"]
            run_on_common_part_only = flask.request.args.get("run_on_common_part_only", "true") == "true"
            reset_tentacle_config = flask.request.args.get("reset_tentacle_config", False)
            success, reply = models.start_backtesting_using_specific_files(files,
                                                                           source,
                                                                           reset_tentacle_config,
                                                                           run_on_common_part_only)
        if success:
            web_interface.send_backtesting_status()
            return util.get_rest_reply(flask.jsonify(reply))
        else:
            return util.get_rest_reply(reply, 500)

    elif flask.request.method == 'GET':
        if flask.request.args:
            target = flask.request.args["update_type"]
            if target == "backtesting_report":
                source = flask.request.args["source"]
                backtesting_report = models.get_backtesting_report(source)
                return flask.jsonify(backtesting_report)

        else:
            return flask.render_template('backtesting.html',
                                         activated_trading_mode=models.get_config_activated_trading_mode(),
                                         data_files=models.get_data_files_with_description())
Example #3
0
def config_tentacle():
    if flask.request.method == 'POST':
        tentacle_name = flask.request.args.get("name")
        action = flask.request.args.get("action")
        success = True
        response = ""
        if action == "update":
            request_data = flask.request.get_json()
            success, response = models.update_tentacle_config(
                tentacle_name, request_data)
        elif action == "factory_reset":
            success, response = models.reset_config_to_default(tentacle_name)
        if success:
            return util.get_rest_reply(flask.jsonify(response))
        else:
            return util.get_rest_reply(response, 500)
    else:
        if flask.request.args:
            tentacle_name = flask.request.args.get("name")
            missing_tentacles = set()
            media_url = flask.url_for("tentacle_media", _external=True)
            tentacle_class, tentacle_type, tentacle_desc = models.get_tentacle_from_string(
                tentacle_name, media_url)
            evaluator_config = models.get_evaluator_detailed_config(media_url,
                                                                    missing_tentacles) if tentacle_type == "strategy" and \
                                                                                          tentacle_desc[
                                                                                              models.REQUIREMENTS_KEY] == [
                                                                                              "*"] else None
            strategy_config = models.get_strategy_config(media_url,
                                                         missing_tentacles) if tentacle_type == "trading mode" and \
                                                                               len(tentacle_desc[
                                                                                       models.REQUIREMENTS_KEY]) > 1 else None
            evaluator_startup_config = models.get_evaluators_tentacles_startup_activation() \
                if evaluator_config or strategy_config else None
            tentacle_commands = models.get_tentacle_user_commands(
                tentacle_class)
            return flask.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=models.
                get_config_activated_trading_mode(),
                data_files=models.get_data_files_with_description(),
                missing_tentacles=missing_tentacles,
                user_commands=tentacle_commands,
                current_profile=models.get_current_profile())
        else:
            return flask.render_template('config_tentacle.html')