输入/搜索内容
内置函数
Global
Version
IsVirtual
GetOS
GetPid
GetMeta
Sleep
Unix
UnixNano
_D
GetCommand
GetLastError
SetErrorFilter
_N
_C
_Cross
JSON.parse
JSON.stringify
Encode
MD5
UUID
Log
Market
Trade
Account
Futures
Exchange
IO
Network
Storage
Threads
TA
Talib
OS
结构体
内置变量与常量
通用约定
交易所

获取策略交互命令。

GetCommand()
GetCommand(timeout)

示例

  • 检测交互命令并且在检测到交互命令时使用Log函数输出交互命令。

    javascript
    function main(){ while(true) { var cmd = GetCommand() if (cmd) { Log(cmd) } Sleep(1000) } }
    python
    def main(): while True: cmd = GetCommand() if cmd: Log(cmd) Sleep(1000)
    rust
    fn main() { loop { // Rust 的 GetCommand() 需要传入超时参数(毫秒),传入 -1 表示不等待;返回 Option<String>,无命令时为 None if let Some(cmd) = GetCommand(-1) { Log!(cmd); } Sleep(1000); } }
  • 例如策略交互控件中添加了一个不带输入框的控件,交互控件命名为:buy,控件描述信息为:买入,这是一个按钮控件。继续添加一个带输入框的控件,交互控件名为:sell,控件描述信息为:卖出,这是一个由按钮和输入框组合起来的交互控件。策略中设计交互代码来响应不同交互控件。

    javascript
    function main() { while (true) { LogStatus(_D()) var cmd = GetCommand() if (cmd) { Log("cmd:", cmd) var arr = cmd.split(":") if (arr[0] == "buy") { Log("Buy, this control has no quantity") } else if (arr[0] == "sell") { Log("Sell, this control has quantity:", arr[1]) } else { Log("Other control triggered:", arr) } } Sleep(1000) } }
    python
    def main(): while True: LogStatus(_D()) cmd = GetCommand() if cmd: Log("cmd:", cmd) arr = cmd.split(":") if arr[0] == "buy": Log("Buy, this control has no quantity") elif arr[0] == "sell": Log("Sell, this control has quantity:", arr[1]) else: Log("Other control triggered:", arr) Sleep(1000)
    rust
    fn main() { loop { LogStatus!(_D(None)); if let Some(cmd) = GetCommand(-1) { Log!("cmd:", cmd); let arr: Vec<&str> = cmd.split(':').collect(); if arr[0] == "buy" { Log!("Buy, this control has no quantity"); } else if arr[0] == "sell" { Log!("Sell, this control has quantity:", arr[1]); } else { Log!("Other control triggered:", arr); } } Sleep(1000); } }

返回值

类型描述

string / 空值

返回的命令格式为ControlName:Data。ControlName是控件名称,Data是控件中输入的数据。如果交互控件没有输入框、下拉框等组件(例如:不带输入框的按钮控件)则返回的命令格式为ControlName,仅返回控件名称。没有交互命令时返回空值。

参数

名称类型必填描述

timeout

number

否

等待交互命令的超时时间,单位毫秒。设置为-1时不等待,没有命令立即返回(JavaScript、Python不传该参数时即为-1);设置为0时一直阻塞等待,直到收到命令;设置为正数时最多等待该毫秒数。Rust语言必须传入该参数,轮询时传入-1。

参考

备注

回测系统中不起作用。