OtherStruct
HttpQuery-options
This JSON structure is used to configure various parameters for HTTP requests sent by HttpQuery and HttpQuery_Go functions.
Attributes
| Name | Type | Description |
method | string | HTTP request method, for example: |
body | string | Request body content. For example, in POST requests, body can contain form data, JSON data, text, etc. |
charset | string | Character set encoding. Used to specify the encoding method for text data in the request body, for example: |
cookie | string | Cookie is a small piece of data used to store and exchange state information between the client (usually a browser) and the server. |
debug | bool | Debug mode switch. When set to true, the HttpQuery function call will return the complete HTTP response message; when set to false, it only returns the data in the response message Body. |
headers | JSON | HTTP request header information, existing as key-value pairs (JSON structure), used to pass various information such as content type, authentication information, cache control, etc. |
timeout | number | Timeout setting in milliseconds. Setting 1000 means 1 second timeout. |
See Also
Remarks
Usage example:
javascript
function main() {
var options = {
method: "POST",
body: "a=10&b=20&c=30",
charset: "UTF-8",
cookie: "session_id=12345; lang=en",
debug: false,
headers: {"TEST-HTTP-QUERY": "123"},
timeout: 1000
}
var ret = HttpQuery("http://127.0.0.1:8080", options)
Log(ret)
}
HTTP message sent when the above code is executed:
log
POST / HTTP/1.1
Content-Type: application/x-www-form-urlencoded
Cookie: session_id=12345; lang=en
Host: 127.0.0.1:8080
Test-Http-Query: 123
Transfer-Encoding: chunked
User-Agent: Mozilla/5.0 (Macintosh; ...
Accept-Encoding: gzip, deflate, br
e
a=10&b=20&c=30
0
HttpQuery-return
This JSON structure is the data structure returned by the HttpQuery function in debug mode when the debug field is specified as true in the parameter options structure.
Attributes
| Name | Type | Description |
StatusCode | number | HTTP status code |
Header | JSON | Request header information |
Cookies | array | Cookie information |
Trace | JSON | Complete path information of the request |
Length | number | Message length |
Body | string | Message content |
See Also
Remarks
Example of returned JSON data structure:
json
{
"StatusCode": 302,
"Header": {
"Content-Type": ["text/html"],
// ...
},
"Cookies": [{
// ...
}],
"Trace": {},
"Length": 154,
"Body": "..."
}
LogStatus-table
This JSON structure is used to configure the table content displayed in the strategy status bar.
Attributes
| Name | Type | Description |
type | string | Used to set the type of UI control to be parsed and displayed. For status bar tables, it is fixed as: |
title | string | Used to set the title of the status bar table. |
cols | array | Used to set the column headers of the status bar table. The first element of the array is the title of the first column, and so on. |
rows | array | Used to set the row data of the status bar table. The first element of this rows array (two-dimensional array) is also an array structure. The length of this array structure should be consistent with the number of table columns (elements in the array correspond one-to-one with table column names), representing the first row of data in the table. |
See Also
Remarks
javascript
function main() {
var tbl = {
type: "table",
title: "标题",
cols: ["列1", "列2", "列3"],
rows: [
["行1列1", "行1列2", "行1列3"],
["行2列1", "行2列2", "行2列3"],
["行3列1", "行3列2", "行3列3"],
]
}
LogStatus("`" + JSON.stringify(tbl) + "`")
}
LogStatus-btnTypeOne
This JSON structure is used to configure button controls in the status bar. The button control JSON structure can be embedded into the status bar table JSON structure. This is a legacy version structure that the platform still supports for compatibility, but it is recommended to use the latest version of the button JSON structure.
Status bar button control construction example (after button click trigger, the popup contains a single input control, constructed through the input field):
json
{
"type": "button",
"cmd": "open",
"name": "Open Position",
"input": {
"name": "Position Size",
"type": "number",
"defValue": 1
}
}
The controls in the popup triggered by clicking the status bar button are configured through the input or group fields.
Attributes
| Name | Type | Description |
type | string | For button controls, fixed as: |
class | string | Button type setting. |
name | string | The text displayed on the button control, i.e., the button name. |
cmd | string | The interactive command content sent to the strategy when the button control triggers a click operation. |
description | string | Description information for the button control. This description is displayed when the mouse hovers over the button in the status bar. |
disabled | bool | Set the button as disabled (true) or enabled (false). |
input | JSON | When constructing status bar buttons for interaction, data input is supported. The interaction command is ultimately captured by the
Description of each field in the above JSON structure:
Extended fields for dropdown type controls:
|
group | array | The |
See Also
Remarks
Example of class attribute values for button JSON structure in status bar:
javascript
function main() {
var table = {
type: "table",
title: "Status Bar Button Styles",
cols: ["Default", "Primary", "Success", "Info", "Warning", "Danger"],
rows: [
[
{"type":"button", "class": "btn btn-xs btn-default", "name": "Default"},
{"type":"button", "class": "btn btn-xs btn-primary", "name": "Primary"},
{"type":"button", "class": "btn btn-xs btn-success", "name": "Success"},
{"type":"button", "class": "btn btn-xs btn-info", "name": "Info"},
{"type":"button", "class": "btn btn-xs btn-warning", "name": "Warning"},
{"type":"button", "class": "btn btn-xs btn-danger", "name": "Danger"}
]
]
}
LogStatus("`" + JSON.stringify(table) + "`")
}
group field and input field usage example:
javascript
function main() {
// Status bar button control (implemented with input field) - The dropdown control on the page triggered by testBtn1 button uses options field to set options and defValue field to set default option. This differs from other examples in this chapter that directly use defValue to set options.
var testBtn1 = {
type: "button",
name: "testBtn1",
cmd: "cmdTestBtn1",
input: {name: "testBtn1ComboBox", type: "selected", options: ["A", "B"], defValue: 1}
}
/*
Status bar button control (implemented with input field) - The dropdown control on the page triggered by testBtn2 button uses options field to set options. The options field supports not only strings,
but also ```{text: "description", value: "value"}``` structure. Use defValue field to set default option, which can be multiple selections (implemented through array structure). Multiple selection requires setting additional field multiple to true.
*/
var testBtn2 = {
type: "button",
name: "testBtn2",
cmd: "cmdTestBtn2",
input: {
name: "testBtn2MultiComboBox",
type: "selected",
description: "Implement dropdown multi-select",
options: [{text: "Option A", value: "A"}, {text: "Option B", value: "B"}, {text: "Option C", value: "C"}],
defValue: ["A", "C"],
multiple: true
}
}
// Status bar grouped button control (implemented with group field) - The dropdown control on the page triggered by testBtn3 button uses options field to set options, and also supports directly using defValue to set options.
var testBtn3 = {
type: "button",
name: "testBtn3",
cmd: "cmdTestBtn3",
group: [
{name: "comboBox1", label: "labelComboBox1", description: "Dropdown 1", type: "selected", defValue: 1, options: ["A", "B"]},
{name: "comboBox2", label: "labelComboBox2", description: "Dropdown 2", type: "selected", defValue: "A|B"},
{name: "comboBox3", label: "labelComboBox3", description: "Dropdown 3", type: "selected", defValue: [0, 2], multiple: true, options: ["A", "B", "C"]},
{
name: "comboBox4",
label: "labelComboBox4",
description: "Dropdown 4",
type: "selected",
defValue: ["A", "C"],
multiple: true,
options: [{text: "Option A", value: "A"}, {text: "Option B", value: "B"}, {text: "Option C", value: "C"}, {text: "Option 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)
}
}
LogStatus-btnTypeTwo
This JSON structure is used to configure button controls in the status bar. The button control JSON structure can be embedded into the status bar table JSON structure. This is the latest version of the button JSON structure.
Status bar button control construction example (after the button is clicked, a popup contains multiple input controls, constructed through the group field):
json
{
"type": "button",
"cmd": "open",
"name": "Open Position",
"group": [{
"type": "selected",
"name": "tradeType",
"label": "Order Type",
"description": "Market order, Limit order",
"default": 0,
"group": "Trading Settings",
"settings": {
"options": ["Market Order", "Limit Order"],
"required": true,
}
}, {
"type": "selected",
"name": "direction",
"label": "Trade Direction",
"description": "Buy, Sell",
"default": "buy",
"group": "Trading Settings",
"settings": {
"render": "segment",
"required": true,
"options": [{"name": "Buy", "value": "buy"}, {"name": "Sell", "value": "sell"}],
}
}, {
"type": "number",
"name": "price",
"label": "Price",
"description": "Order price",
"group": "Trading Settings",
"filter": "tradeType==1",
"settings": {
"required": true,
}
}, {
"type": "number",
"name": "amount",
"label": "Order Amount",
"description": "Order quantity",
"group": "Trading Settings",
"settings": {
"required": true,
}
}],
}
The controls in the popup triggered by clicking the status bar button control are set through the input or group field.
Attributes
| Name | Type | Description |
type | string | For button controls, this field is fixed as: |
name | string | The text displayed on the button control, i.e., the button name. |
cmd | string | The interactive command content sent to the strategy when the button control triggers a click action. |
input | JSON | When constructing status bar buttons for interaction, input data is also supported. The interaction commands are ultimately captured by the Compared to the old version of the input structure, the new version adds some new fields and changes:
Description and explanation of each field in the above JSON structure:
|
group | array | The |
See Also
Remarks
Supports bilingual settings:
json
{
type:'selected',
name:'test',
label:'选项|options',
description:'描述|description',
default:0, // Here default value is set to 0, representing the value in {name:'xxx|yyy',value:0} option
filter:'a>1&&a<10',
group:'分组|group',
settings:{
multiple:true,
customizable:true,
options:[{name:'xxx|yyy',value:0}]
}
}
Chart-options
This JSON is used to configure chart settings for the custom plotting function Chart(). The chart library uses Highcharts. The following lists several basic configuration fields.
Attributes
| Name | Type | Description |
__isStock | string | Platform extension field. When set to true, uses Highstocks chart; when set to false, uses Highcharts chart. |
extension | JSON |
|
title | string | Chart title |
xAxis | JSON | X-axis configuration. |
yAxis | JSON | Y-axis configuration. |
series | JSON | Chart data series. |
See Also
Remarks
Simple plotting example:
javascript
// This chart is an object in JavaScript. Before using the Chart function, you need to declare an object variable chart for configuring the chart
var chart = {
// This field marks whether the chart is a stock chart. Interested users can change it to false and run to see the effect
__isStock: true,
// Zoom tool
tooltip: {xDateFormat: '%Y-%m-%d %H:%M:%S, %A'},
// Title
title : { text : 'Spread Analysis Chart'},
// Range selector
rangeSelector: {
buttons: [{type: 'hour',count: 1, text: '1h'}, {type: 'hour',count: 3, text: '3h'}, {type: 'hour', count: 8, text: '8h'}, {type: 'all',text: 'All'}],
selected: 0,
inputEnabled: false
},
// Horizontal axis (X-axis), currently set type is datetime
xAxis: { type: 'datetime'},
// Vertical axis (Y-axis), default values adjust with data size
yAxis : {
// Title
title: {text: 'Spread'},
// Whether to enable right-side Y-axis
opposite: false
},
// Data series, this property stores various data series (lines, candlestick charts, labels, etc.)
series : [
// Index 0, data array stores data for this index series
{name : "line1", id : "Line1,buy1Price", data : []},
// Index 1, dashStyle:'shortdash' is set to display as dashed line
{name : "line2", id : "Line2,lastPrice", dashStyle : 'shortdash', data : []}
]
}
function main(){
// Call Chart function to initialize the chart
var ObjChart = Chart(chart)
// Clear
ObjChart.reset()
while(true){
// Get the timestamp of this polling cycle, i.e., millisecond timestamp, used to determine the position on the chart's X-axis
var nowTime = new Date().getTime()
// Get market data
var ticker = _C(exchange.GetTicker)
// Get the best bid price from the market data return value
var buy1Price = ticker.Buy
// Get the last traded price. To prevent the two lines from overlapping, we add 1
var lastPrice = ticker.Last + 1
// Pass timestamp as X value and best bid price as Y value to data series at index 0
ObjChart.add(0, [nowTime, buy1Price])
// Same as above
ObjChart.add(1, [nowTime, lastPrice])
Sleep(2000)
}
}
KLineChart-options
This JSON is used to configure the chart settings for the custom drawing function KLineChart. Only a few basic configuration fields are listed below.
Attributes
| Name | Type | Description |
overlay | bool | Whether to draw on the main chart. |
xAxis | JSON | X-axis configuration parameters. |
yAxis | JSON | Y-axis configuration parameters. |
candle | JSON | Candlestick chart configuration parameters. |
See Also
Remarks
SetData-data
This JSON is used to set the data to be loaded by the exchange.SetData() function. This JSON data uses an array structure, where each element is also an array with the format [time, data].
Attributes
| Name | Type | Description |
time | number | The timestamp of the data, used to mark the time corresponding to this data entry. |
data | string / number / bool / object / array / any (any type supported by the platform) | data is the specific data content corresponding to a certain time in the data loaded by the |
See Also
Remarks
Example of loading data in the backtesting system and retrieving data when the strategy backtest is running:
javascript
/*backtest
start: 2020-01-21 00:00:00
end: 2020-02-12 00:00:00
period: 1d
basePeriod: 1d
exchanges: [{"eid":"Bitfinex","currency":"BTC_USD"}]
*/
function main() {
exchange.SetData("test", [[1579536000000, _D(1579536000000)], [1579622400000, _D(1579622400000)], [1579708800000, _D(1579708800000)]])
while(true) {
Log(exchange.GetData("test"))
Sleep(1000 * 60 * 60 * 24)
}
}
EventLoop-return
This JSON is the data structure returned by the EventLoop() function. The EventLoop() function monitors the following events: 1. Any WebSocket readable data events; 2. Completion events of concurrent tasks from exchange.Go() and HttpQuery_Go() functions; 3. Message events sent by threads created using the threading.Thread() function in JavaScript language strategies.
Attributes
| Name | Type | Description |
Seq | number | Event sequence number. |
Event | string | Event name. |
ThreadId | number | Event thread ID. |
Index | number | Event index. |
Nano | number | Nanosecond timestamp. |
See Also
Remarks
When using the exchange.Go() function for concurrent requests, the event data structure returned by the EventLoop() function.
json
{
"Seq":1,
"Event":"Exchange_GetTrades",
"ThreadId":0,
"Index":3,
"Nano":1682068771309583400
}
When concurrent execution threads in JavaScript language strategies (created by the threading.Thread() function) use the thread object's postMessage() function to send messages, the EventLoop() function in the receiving thread will monitor the following event data structure:
json
{
"Seq":4,
"Event":"thread",
"ThreadId":1,
"Index":0,
"Nano":1727592066508674000
}
DBExec-return
This JSON is the data structure returned by the DBExec() function; this JSON data structure is also returned when executing SQL statements using the exec() method of objects created by the Dial() function.
Attributes
| Name | Type | Description |
columns | array | Column names of the queried data, string array. |
values | array | The specific data queried, where each data item corresponds to the column names. The values field is a two-dimensional array, with each element being an array representing one data record. |
See Also
Remarks
Example of querying data from database:
json
{
"columns":["TS","HIGH","OPEN","LOW","CLOSE","VOLUME"],
"values":[
[1518970320000,100,99.1,90,100,12345.6],
[1518960320000,100,99.1,90,100,12345.6]
]
}
Thread.join-return
This JSON is the data structure returned by the join() member function of the Thread object, used to store information related to concurrent threads in JavaScript language strategies. The Thread object refers to a thread object created via threading.Thread().
Attributes
| Name | Type | Description |
id | number | Thread ID. |
terminated | bool | Whether the thread was forcibly terminated. |
elapsed | number | Thread execution time (nanoseconds). |
ret | number | Return value of the thread function. |
See Also
Remarks
The following code tests the timeout mechanism of the join() function of the Thread object and prints the return value of the join() function.
javascript
function testFunc() {
for (var i = 0; i < 5; i++) {
Log(i)
Sleep(300)
}
}
function main() {
var t1 = threading.Thread(testFunc)
Log(t1.join(1000)) // undefined
Log(t1.join()) // {"id":1,"terminated":false,"elapsed":1506864000}
}