# Chaining

Chain any commands by using

* the `;` operator for sequential processing, one after another. Note that the next command does not await the previous command to "finish" or succeed.
* the `&` operator for parallel processing of the chained commands at once.

While they are essentially the same you should use `;` around `sleep` commands. Generally it might be a semantic help for different use cases. Both can be used with or without spaces on either side, use to your liking.

For example:

`buy 1000$ btcusdt & buy 2000$ ethusdt`

You could think of it as "do this AND do that at once". While:

`buy 1000$; sleep 5s; buy 1000$ at -1%`   &#x20;

you could think of it as "do this, THEN wait 5s, THEN do that".

{% hint style="success" %}
Note that when you want to chain commands which are "dependant" on each other, latencies might vary and work against you. E.g. if you attempt to `buy 1000$  ; sell 100% at 1% reduce` the exchange might process your reduce order before your position has been opened. Best to incorporate a short sleep here.
{% endhint %}

#### Sleep

The `sleep` command introduce a timeout inside sequential command chains and allows for durational commands and ordering in the CLI. The syntax is: `sleep <duration>` where unit supports `ms`, `s`, `m` - seconds `s` are applied when the unit is omited. A max duration of 10min applies.\
Examples:&#x20;

`sleep 500`,    `sleep 1s`,    `sleep 2m`

#### Task Management

Every chained command using sleep (and repeat command) has an ID assigned which is a session-local rolling counter maintained by the CLI. The IDs are shown via: Console log, `tasks` command and the Activity component.

Inside the CLI the following commands are available for control:

```
tasks               # list active CLI tasks only (IDs + command string)
kill                # kill the most-recent CLI task
kill 3              # kill task ID 3
kill all            # kill every running CLI task
```

#### UI for tasks via Activity component

Use the Activity component to monitor ongoing durational chained tasks. You can manually cancel repeat tasks .


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.insilicoterminal.com/documentation/terminal-cli/chaining.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
