GetCommand
Get the strategy's interactive command.
GetCommand()
GetCommand(timeout)Examples
-
Detect interactive commands, and when an interactive command is detected, use the
Logfunction to output it.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's GetCommand() requires a timeout parameter (milliseconds); -1 means do not wait. It // returns Option<String>, which is None when there is no command if let Some(cmd) = GetCommand(-1) { Log!(cmd); } Sleep(1000); } } -
For example, in the strategy's interactive controls, add a control without an input box, name it
buy, with the control descriptionBuy; this is a button control. Then add a control with an input box, name itsell, with the control descriptionSell; this is an interactive control composed of a button and an input box. Write interactive code in the strategy to respond to the different interactive controls.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); } }
Returns
| Type | Description |
string / null value | The returned command format is |
Arguments
| Name | Type | Required | Description |
timeout | number | No | The timeout for waiting for an interactive command, in milliseconds. When set to |
See Also
Remarks
This function is invalid in the backtesting system.