The resource loading... loading...

Explore FMZ: the newest application of the status button

Author: Inventors quantify - small dreams, Created: 2024-07-25 15:20:47, Updated: 2024-07-26 16:10:27

img

随着量化交易平台API接口的一次重大更新,平台的策略界面参数、交互控件等功能进行了调整,并新增了许多功能。之前的文章详细介绍了界面参数和交互控件的更新内容。本篇继续探讨FMZ.COM新引入的状态栏按钮的应用。

每位策略开发者都希望构建一个简单易用、功能强大且设计简约的UI界面。为了实现这一标准,FMZ.COM不遗余力地升级平台功能,提升用户体验。直接在策略页面状态栏中设计交互控件,正是基于这一需求的升级。

In the following, let's look at the application of multi-variety strategies in different scenarios.

Multi-strategy scenarios

Whether it's a fully automatic multi-variety timing policy or a semi-manual multi-variety timing policy. The policy UI will require some functional interactive buttons, such as stop, stop loss, all stock clearance, plan assignment, etc.

So let's explore the new features of the status button in one of the simplest use cases.

BTC_USDT perpetual contract, ETH_USDT perpetual contract, LTC_USDT perpetual contract, BNB_USDT perpetual contract, SOL_USDT perpetual contract is also available.

While executing automatic trades, we want to design a trade button for each variety in the status bar of the strategy interface. However, this trade button requires a series of detailed settings, such as:

  • Order type: List of restricted prices / List of market prices.
  • The following order quantity: quantity.
  • The price of the order:
  • The transaction direction is: buy (more) sell (less).

Prior to this platform upgrade, the status bar button was merely triggering a button interaction message. There was no way to bind a series of controls to set up complex messages. This update to the interaction addressed this need.

Design examples:

// 设置操作的各个品种 BTC_USDT.swap 为FMZ平台定义的品种格式,表示BTC的U本位永续合约
var symbols = ["BTC_USDT.swap", "ETH_USDT.swap", "LTC_USDT.swap", "BNB_USDT.swap", "SOL_USDT.swap"]

// 根据按钮模板构造按钮
function createBtn(tmp, group) {
    var btn = JSON.parse(JSON.stringify(tmp))
    _.each(group, function(eleByGroup) {
        btn["group"].unshift(eleByGroup)
    })

    return btn
}

function main() {
    LogReset(1)

    var arrManager = []
    _.each(symbols, function(symbol) {
        arrManager.push({
            "symbol": symbol,
        })
    })

    // Btn
    var tmpBtnOpen = {
        "type": "button",
        "cmd": "open",
        "name": "开仓下单",
        "group": [{
            "type": "selected",
            "name": "tradeType",
            "label": "下单类型",
            "description": "市价单、限价单",
            "default": 0,
            "group": "交易设置",
            "settings": {
                "options": ["市价单", "限价单"],
                "required": true,
            }
        }, {
            "type": "selected",
            "name": "direction",
            "label": "交易方向",
            "description": "买入、卖出",
            "default": "buy",
            "group": "交易设置",
            "settings": {
                "render": "segment",
                "required": true,
                "options": [{"name": "买入", "value": "buy"}, {"name": "卖出", "value": "sell"}],
            }
        }, {
            "type": "number",
            "name": "price",
            "label": "价格",
            "description": "订单的价格",
            "group": "交易设置",
            "filter": "tradeType==1",
            "settings": {
                "required": true,
            }
        }, {
            "type": "number",
            "name": "amount",
            "label": "下单量",
            "description": "订单的下单量",
            "group": "交易设置",
            "settings": {
                "required": true,
            }
        }],
    }

    while (true) {
        var tbl = {"type": "table", "title": "dashboard", "cols": ["symbol", "actionOpen"], "rows": []}
        _.each(arrManager, function(m) {
            var btnOpen = createBtn(tmpBtnOpen, [{"type": "string", "name": "symbol", "label": "交易品种", "default": m["symbol"], "settings": {"required": true}}])
            tbl["rows"].push([m["symbol"], btnOpen])
        })
        
        var cmd = GetCommand()
        if (cmd) {
            Log("收到交互:", cmd)
            
            // 解析交互消息: open:{"symbol":"LTC_USDT.swap","tradeType":0,"direction":"buy","amount":111}
            // 根据第一个冒号:之前的指令判断是哪种按钮模板触发的消息
            var arrCmd = cmd.split(":", 2)
            if (arrCmd[0] == "open") {
                var msg = JSON.parse(cmd.slice(5))
                Log("交易品种:", msg["symbol"], ",交易方向:", msg["direction"], ",订单类型:", msg["tradeType"] == 0 ? "市价单" : "限价单", msg["tradeType"] == 0 ? ",订单价格:当前市价" : ",订单价格:" + msg["price"], ",订单数量:", msg["amount"])
            }
        }

        // 输出状态栏信息
        LogStatus(_D(), "\n", "`" + JSON.stringify(tbl) + "`")
        Sleep(1000)
    }
}

First of all, let's look at the running effects and explain in detail the design of the button controls. The policy code runs as follows:

img

Click on a button and you'll see a bullet box with specific information about the order:

img

After filling in the opening information we have designed.

img

You can see that the policy has received the message, and in the code we have analyzed the message and the settings to output this order.

First we define a button template, a JSON object, and we assign it a value to the variable tmpBtnOpen.

    {
        "type": "button",       // 状态栏输出控件的类型,目前仅支持按钮
        "cmd": "open",          // 当按钮触发时,策略中GetCommand函数收到的消息前缀,例如这个例子:open:{"symbol":"LTC_USDT.swap","tradeType":0,"direction":"buy","amount":111}
        "name": "开仓下单",      // 策略界面,状态栏上的按钮上显示的内容,参考上图
        "group": [{             // 当按钮触发时,弹框中的控件配置设置,这一层的group字段值是一个数组,弹框中的控件根据这个数组顺序自上而下排列
            "type": "selected",               // 第一个控件类型是:selected ,下拉框 
            "name": "tradeType",              // 当状态栏按钮触发时,消息中包含该控件的设置内容,tradeType就是当前这个下拉框控件输入的值的键名。如果选择第一个选项「市价单」GetCommand函数收到的消息中就包含 "tradeType":0 的键值对信息。
            "label": "下单类型",               // 按钮触发时,弹框中当前控件的标题
            "description": "市价单、限价单",    // 当前控件的说明信息,鼠标放在控件右侧“小问号”图标上就会显示这个说明信息。
            "default": 0,                     // 当前控件的默认值,例如当前是下拉框控件,如果不做选择,默认为下拉框第一个选项,通常下拉框的默认值指的是下拉框选项的索引,即第一个是0,然后是1,以此类推。如果下拉框的选项options是key-value形式则默认值指的是value。
            "group": "交易设置",               // 弹框中的控件如果很多,可以分组,这个字段可以设置分组信息
            "settings": {                     // 当前这个下拉框的具体设置
                "options": ["市价单", "限价单"],   // options和下拉框相关的设置,用于设置下拉框中的选项,这个字段值是一个数组,依次排列下拉框中的选项。
                "required": true,                // required表示是否设置为必选(必填)内容。
            }
        }, {
            "type": "selected",         // 这也是一个下拉框类型
            "name": "direction",
            "label": "交易方向",
            "description": "买入、卖出",
            "default": "buy",
            "group": "交易设置",
            "settings": {
                "render": "segment",   // 和默认下拉框控件不同的是,通过render字段可以把下拉框替换为“分段选择器”,如上图中的“买入/卖出”控件。
                "required": true,
                "options": [{"name": "买入", "value": "buy"}, {"name": "卖出", "value": "sell"}],   // 使用 key-value方式设置options
            }
        }, {
            "type": "number",           // 数值输入框类型控件
            "name": "price",
            "label": "价格",
            "description": "订单的价格",
            "group": "交易设置",
            "filter": "tradeType==1",   // 过滤器,可以用于确定是否显示当前控件,当tradeType==1时,表示是市价单,所以不需要该控件设置价格,所以不显示。
            "settings": {
                "required": true,       // 当该控件激活显示时为必选(必填)
            }
        }, {
            "type": "number",
            "name": "amount",
            "label": "下单量",
            "description": "订单的下单量",
            "group": "交易设置",
            "settings": {
                "required": true,
            }
        }],
    }
  • group As this is just an example, there may be more requirements in actual design use, not limited to the order direction, price, quantity, order type set at the time of opening; there may also be a design of exit rules such as stop loss, stop loss plan assignment; so the new version of the UI supportsgroupFields, which are convenient for grouping together a group of controls in a bullet box, such as the "Transaction Settings" folding setting in the screenshot above.

  • required In the button structuregroupThe controls set in the fields are addedrequiredSet the field to set whether to send interactive messages if it is set to be mandatory but not filled in while in use, and there is a red prompt.

  • filter IncreasedfilterThe field is used to set filter dependencies, for example in the above example if you select the market price list type to place an order, then the order price is not necessary, you can set this totypeFor "number",nameThe control for "price" is hidden.

  • Rendered Fields have been added for the following basic types of controls (type field settings): number, string, selected, boolean.renderTo set up a controller render, each controller has its own multiple rendering components. For example, in the above example, it is more appropriate to render the selected drop-down controller as a "segment selector", since the drop-down box requires two clicks (the first time you open the drop-down box, the second time you select the option), using the drop-down selector component, just click and select the desired option.

The last thing a careful reader might ask is that the screenshot above doesn't show you the control information in the checkbox that says "transaction variety" and that "transaction variety" is not in the "transaction settings" group (i.e.:"group": "交易设置"This setting is implemented.)

Here is a demonstration of a design that binds a button in a status bar table to other information in the status bar, usingcreateBtnFunctions based on templatestmpBtnOpenConstruct the final button structure, and write other information into the button structure during the construction.

// 构造按钮的时候,绑定当前行的品种名称等信息,给按钮的弹框增加一个控件,并排在首位
var btnOpen = createBtn(tmpBtnOpen, [{"type": "string", "name": "symbol", "label": "交易品种", "default": m["symbol"], "settings": {"required": true}}])

So what you end up with is that when you click on the policy interface in the status bar, you're going to see a little bit of a change in the status bar.symbolFor theBNB_USDT.swapWhen this button is pressed, the "trade variety" box in the box is automatically filled in.BNB_USDT.swap

This article presents only a small part of the application of the new version of the UI, and since the overall article can not be too long, we will continue to discuss the design of other demand scenarios in the next article.

Thank you for your support!


More