Sleep
Pauses program execution for a specified period of time.
Sleep(millisecond)Examples
Pause for 10 seconds, then continue.
javascript
function main() {
Sleep(1000 * 10) // Wait for 10 seconds
Log("Waited for 10 seconds")
}
python
def main():
Sleep(1000 * 10) # Wait for 10 seconds
Log("Waited for 10 seconds")
rust
fn main() {
Sleep(1000 * 10); // Wait for 10 seconds
Log!("Waited for 10 seconds");
}Arguments
| Name | Type | Required | Description |
millisecond | number | Yes | Sleep duration, in milliseconds. |
See Also
Remarks
For example, when executing the Sleep(1000) function, the program will sleep for 1 second. This function supports sleep operations of less than 1 millisecond, such as Sleep(0.1). The minimum supported parameter is 0.000001, i.e. nanosecond-level sleep, where 1 nanosecond equals 1e-6 milliseconds.
When writing strategies in Python, for operations such as polling intervals and time waiting, you should use the Sleep(millisecond) function rather than the time.sleep(second) function from Python's time library. This is because if a strategy uses the time.sleep(second) function during backtesting, it will cause the strategy program to actually wait for a period of time (instead of skipping ahead on the backtesting system's time series), resulting in very slow backtesting speed.