输入/搜索内容
内置函数
结构体
Trade
Ticker
Record
Order
OrderBook
Depth
Account
Position
Market
OtherStruct
HttpQuery-options
HttpQuery-return
LogStatus-table
LogStatus-btnTypeOne
LogStatus-btnTypeTwo
Chart-options
KLineChart-options
SetData-data
EventLoop-return
DBExec-return
Thread.join-return
内置变量

该JSON结构用于配置状态栏中的按钮控件,按钮控件JSON结构可以嵌入到状态栏表格JSON结构中。此结构为旧版本结构,平台目前仍然兼容,建议使用最新版本的按钮JSON结构。
状态栏按钮控件构造示例(按钮触发点击后,弹框中包含单个输入控件,通过input字段构造):

json
{ "type": "button", "cmd": "open", "name": "开仓", "input": { "name": "开仓数量", "type": "number", "defValue": 1 } }

状态栏按钮控件点击触发后的弹框中的控件通过inputgroup字段设置。

属性

名称类型描述

type

string

对于按钮控件,固定设置为:button

class

string

按钮类型设置。

name

string

按钮控件上显示的文本,即按钮名称。

cmd

string

按钮控件触发点击操作时,发送给策略的交互命令内容。

description

string

按钮控件的描述信息。当鼠标悬停在状态栏中该按钮上时显示此描述信息。

disabled

bool

设置按钮为禁用(true)或启用(false)。

input

JSON

在构造状态栏按钮进行交互时支持输入数据,交互指令最终由GetCommand()函数捕获。在状态栏按钮控件的JSON数据结构中添加input项,用于配置按钮触发时显示的弹框中的输入控件。
例如,设置input字段值为:

json
{ "name": "开仓数量", "type": "number", "defValue": 1, "description": "test" }

上述JSON结构中各字段描述:

  • name
    状态栏按钮触发点击操作后,弹出的弹框中控件的标题。
  • description
    状态栏按钮触发点击操作后,弹出的弹框中控件的描述信息。
  • type
    状态栏按钮触发点击操作后,弹出的弹框中控件的类型。type字段可取以下值:
    1、"number":数值输入控件。
    2、"string":字符串输入控件。
    3、"selected":下拉框控件。
    4、"boolean":开关控件。
  • defValue
    状态栏按钮触发点击操作后,弹出的弹框中控件的默认值。
    如果是下拉框类型控件(selected),defValue字段用于设置下拉框选项,例如:"input": {"name": "开仓数量", "type": "selected", "defValue": "A|B|C"},下拉框选项的文本描述被设置为A、B、C。

对于下拉框类型控件的扩展字段:

  • options
    状态栏按钮控件触发的页面中的下拉框控件,可以使用options字段设置选项。options字段中的选项不仅支持字符串,还支持使用{text: "描述", value: "值"}结构。使用defValue字段设置默认选项,默认选项可以多选。
  • multiple
    当该字段设置为true时,支持下拉框多选。

group

array

input字段配置状态栏按钮触发点击后弹出的弹框中的单个控件,而group字段用于配置一组控件。group中的元素与input字段值的数据结构一致,请参考input字段的相关描述说明。

参考

备注

状态栏中按钮JSON结构的class属性取值示例:

javascript
function main() { var table = { type: "table", title: "状态栏按钮样式", cols: ["默认", "原始", "成功", "信息", "警告", "危险"], rows: [ [ {"type":"button", "class": "btn btn-xs btn-default", "name": "默认"}, {"type":"button", "class": "btn btn-xs btn-primary", "name": "原始"}, {"type":"button", "class": "btn btn-xs btn-success", "name": "成功"}, {"type":"button", "class": "btn btn-xs btn-info", "name": "信息"}, {"type":"button", "class": "btn btn-xs btn-warning", "name": "告警"}, {"type":"button", "class": "btn btn-xs btn-danger", "name": "危险"} ] ] } LogStatus("`" + JSON.stringify(table) + "`") }

group字段与input字段使用示例:

javascript
function main() { // 状态栏按钮控件(通过设置input字段实现)testBtn1按钮触发的页面中的下拉框控件使用options字段设置选项,使用defValue字段设置默认选项。与本章其他示例中直接使用defValue设置选项的方式不同。 var testBtn1 = { type: "button", name: "testBtn1", cmd: "cmdTestBtn1", input: {name: "testBtn1ComboBox", type: "selected", options: ["A", "B"], defValue: 1} } /* 状态栏按钮控件(通过设置input字段实现)testBtn2按钮触发的页面中的下拉框控件使用options字段设置选项,options字段中的选项不仅支持字符串, 还支持使用```{text: "描述", value: "值"}```结构。使用defValue字段设置默认选项,默认选项可以是多选(通过数组结构实现多选)。多选需要将额外的字段multiple设置为真值(true)。 */ var testBtn2 = { type: "button", name: "testBtn2", cmd: "cmdTestBtn2", input: { name: "testBtn2MultiComboBox", type: "selected", description: "实现下拉框多选", options: [{text: "选项A", value: "A"}, {text: "选项B", value: "B"}, {text: "选项C", value: "C"}], defValue: ["A", "C"], multiple: true } } // 状态栏分组按钮控件(通过设置group字段实现)testBtn3按钮触发的页面中的下拉框控件使用options字段设置选项,也支持直接使用defValue设置选项。 var testBtn3 = { type: "button", name: "testBtn3", cmd: "cmdTestBtn3", group: [ {name: "comboBox1", label: "labelComboBox1", description: "下拉框1", type: "selected", defValue: 1, options: ["A", "B"]}, {name: "comboBox2", label: "labelComboBox2", description: "下拉框2", type: "selected", defValue: "A|B"}, {name: "comboBox3", label: "labelComboBox3", description: "下拉框3", type: "selected", defValue: [0, 2], multiple: true, options: ["A", "B", "C"]}, { name: "comboBox4", label: "labelComboBox4", description: "下拉框4", type: "selected", defValue: ["A", "C"], multiple: true, options: [{text: "选项A", value: "A"}, {text: "选项B", value: "B"}, {text: "选项C", value: "C"}, {text: "选项D", value: "D"}] } ] } while (true) { LogStatus("`" + JSON.stringify(testBtn1) + "`\n", "`" + JSON.stringify(testBtn2) + "`\n", "`" + JSON.stringify(testBtn3) + "`\n") var cmd = GetCommand() if (cmd) { Log(cmd) } Sleep(5000) } }