Interactive Controls in Status Bar
Besides the controls designed in the "Strategy Interaction" section, a strategy can output interactive controls in its status bar. The only interactive control there is the button. For all fields of buttons and input controls, and the format of the command that GetCommand receives after a click, see "Status bar buttons" on the LogStatus page; this page shows the common patterns.
There are three kinds of status bar buttons:
- A plain button: a click opens a confirmation box, and on confirmation the strategy receives
cmd.json{"type": "button", "name": "平仓|Close", "cmd": "close", "description": "平掉全部持仓|close all positions"} - A button with one input control: set it with
input; the strategy receivescmd:value.json{ "type": "button", "name": "开仓|Open", "cmd": "open", "input": {"type": "number", "name": "amount", "label": "开仓数量|amount", "default": 1, "required": true} } - A button with a group of input controls: set them with
group; the strategy receivescmd:JSONkeyed by each control'sname. In this example the price control is shown only when the order type is "limit":json{ "type": "button", "cmd": "order", "name": "下单|Order", "group": [ {"type": "selected", "name": "orderType", "label": "下单方式|order type", "default": 0, "settings": {"options": ["市价单|market", "限价单|limit"]}}, {"type": "number", "name": "price", "label": "价格|price", "settings": {"filter": "orderType==1"}}, {"type": "number", "name": "amount", "label": "数量|amount", "default": 1, "required": true} ] }
When writing these controls:
- Put the display condition in
settings.filter(for example"filter": "orderType==1"), referring to thenameof another control in the same group; afilterat the top level of the control has no effect. - Put
"required": trueat the top level of the control; arequiredinsidesettingshas no effect. - Each line of the status bar can hold only one JSON block wrapped in
`. Output several buttons on separate lines, or put them in a status bar table (several buttons in one cell are written as an array of buttons). - Texts can be bilingual, written as
"中文|English"and shown according to the page language.
To output a button, encode the button object as a JSON string, wrap it in ` and pass it to LogStatus(). In JavaScript:
javascript
function main() {
var btnClose = {"type": "button", "name": "平仓|Close", "cmd": "close"}
var btnOpen = {
"type": "button", "name": "开仓|Open", "cmd": "open",
"input": {"type": "number", "name": "amount", "label": "开仓数量|amount", "default": 1}
}
// one JSON block per line: the two buttons go on two lines
LogStatus("`" + JSON.stringify(btnClose) + "`\n`" + JSON.stringify(btnOpen) + "`")
while (true) {
var cmd = GetCommand()
if (cmd) {
Log("command received:", cmd) // "close", "open:2"
}
Sleep(1000)
}
}
For buttons in status bar tables, button colors and sizes (class), multi-select and customizable drop-downs, sliders, date pickers and other control styles, see LogStatus.
Status bar display components
Besides text, tables and buttons, LogStatus accepts objects with a type directly and the status bar renders them as components: grid and tabs handle layout, while kpi (KPI card), stat (key-value list), chart (line, bar and area charts), sparkline, gauge, progress, pie, histogram, heatmap, calendar, timeline, markdown, alert and badge display data. Components are display-only and can share a grid with buttons and tables:
javascript
function main() {
var btn = {type: "button", name: "平仓|Close", cmd: "close"}
while (true) {
var ticker = exchange.GetTicker()
if (ticker) {
LogStatus({type: "grid", cols: 2, items: [
{type: "kpi", title: "Last price", value: ticker.Last},
btn // no backticks needed for a button inside a grid
]})
}
var cmd = GetCommand()
if (cmd) {
Log("Command received:", cmd)
}
Sleep(1000)
}
}
For the fields of every component and examples in three languages see Status Bar Components; for the input forms (objects, backticks, several arguments) see LogStatus.