Type/to search
Built-in Functions
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
Structures
Built-in Variables and Constants
Conventions
Exchanges

Get the strategy's interactive command.

GetCommand()
GetCommand(timeout)

Examples

  • Detect interactive commands, and when an interactive command is detected, use the Log function to output it.

    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'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 description Buy; this is a button control. Then add a control with an input box, name it sell, with the control description Sell; 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.

    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); } }

Returns

TypeDescription

string / null value

The returned command format is ControlName:Data, where ControlName is the name of the control and Data is the data entered in the control. If the interactive control does not contain input components such as an input box or dropdown box (for example, a button control without an input box), then the returned command format is ControlName, i.e. only the control name is returned. When there is no interactive command, a null value is returned.

Arguments

NameTypeRequiredDescription

timeout

number

No

The timeout for waiting for an interactive command, in milliseconds. When set to -1, it does not wait and returns immediately if there is no command (this is the default when the parameter is omitted in JavaScript and Python); when set to 0, it blocks until a command is received; when set to a positive number, it waits at most that many milliseconds. In Rust this parameter is required; pass -1 when polling.

See Also

Remarks

This function is invalid in the backtesting system.