GetCommand
获取策略交互命令。
GetCommand()
GetCommand(timeout)示例
-
检测交互命令并且在检测到交互命令时使用
Log函数输出交互命令。javascriptfunction main(){ while(true) { var cmd = GetCommand() if (cmd) { Log(cmd) } Sleep(1000) } }pythondef main(): while True: cmd = GetCommand() if cmd: Log(cmd) Sleep(1000)rustfn main() { loop { // Rust 的 GetCommand() 需要传入超时参数(毫秒),传入 -1 表示不等待;返回 Option<String>,无命令时为 None if let Some(cmd) = GetCommand(-1) { Log!(cmd); } Sleep(1000); } } -
例如策略交互控件中添加了一个不带输入框的控件,交互控件命名为:
buy,控件描述信息为:买入,这是一个按钮控件。继续添加一个带输入框的控件,交互控件名为:sell,控件描述信息为:卖出,这是一个由按钮和输入框组合起来的交互控件。策略中设计交互代码来响应不同交互控件。javascriptfunction 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) } }pythondef 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)rustfn 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 / 空值 | 返回的命令格式为 |
参数
| 名称 | 类型 | 必填 | 描述 |
timeout | number | 否 | 等待交互命令的超时时间,单位毫秒。设置为 |
参考
备注
回测系统中不起作用。