# Commands overview

> How a ZB Connector command message is built: the license and action fields, units, targeting positions, expiry, limits and the list of commands.

Source: https://zb-connector.com/docs/commands/overview/

A command is a JSON object. It always names your license and the action to run, plus the fields that action needs.

**Simple version**

Send a JSON message with `license` (your key), `action` (what to do, such as `long` or `closeAll`) and the fields of that action, for example `symbol` and `volume`. Names are case-sensitive and volume is in lots. The reply HTTP 200 means the command is queued for your EA, not that it ran. Anything the webhook can check up front, such as a missing field, is refused with HTTP 422 and a readable message.

**The shape of every command**

```json
{
  "license": "YOUR_LICENSE_KEY",
  "action": "long",
  "symbol": "EURUSD",
  "volume": 0.01
}
```

**Advanced version**

## Units

| Field | Unit |
| --- | --- |
| `volume` | Lots. The EA rounds it to the symbol’s lot step and keeps it between the symbol’s minimum and maximum. |
| `sl`, `tp` on `long` and `short` | Price levels by default. If the EA input **Stop level mode** is pips or ticks, they are distances from the entry price. `0` means none. |
| `sl`, `tp` on `moveStops` | Always price levels, whatever the Stop level mode says. |
| `offset`, `trailDistance` | Pips. The EA counts a pip as 10 times the symbol’s point, for every symbol. |
| `percentage` | Percent of the position, above 0 and up to 100. |

Number fields also accept numeric text such as `"0.01"`. `positionID` must be text.

## Finding a position

Commands that act on an open position find it by `positionID`, the label you gave it when you opened it (it becomes the MT5 order comment), or by `ticket`. If an open command carries no `positionID`, the server adds one (`CMD` followed by a number). A `positionID` that is all digits and matches no comment is also compared with the ticket. Use short, unique labels, because some commands act on every position that matches.

## Checks before queuing

The webhook checks the license, then the command. It refuses an unknown action, an unknown or missing field, a wrong type and an out-of-range value with HTTP 422, and nothing is queued. Names and actions are case-sensitive: `Long` is not `long`. The reply for a valid command is HTTP 200 with `"status": "received"`. What happens next is in [how delivery works](https://zb-connector.com/docs/reliability/how-delivery-works/).

## Expiry and limits

-   A command that the EA does not collect within 5 minutes expires and is never run late.
-   Each license can send 120 messages per minute. Beyond that the webhook answers HTTP 429.
-   The EA can refuse a command for its own reasons, such as a position limit or a tripped safeguard. The reason appears in the MT5 Experts log.

## The commands

Each command has its own page with fields, examples and errors, and the [cheat sheet](https://zb-connector.com/docs/commands/cheatsheet/) lists them on one page.

### Open positions

-   [`long`](https://zb-connector.com/docs/commands/long/): Open a buy (long) market position.
-   [`short`](https://zb-connector.com/docs/commands/short/): Open a sell (short) market position.

### Close positions

-   [`close_percentage`](https://zb-connector.com/docs/commands/close_percentage/): Close a percentage of one position.
-   [`closeAll`](https://zb-connector.com/docs/commands/closeall/): Close every open position (long and short), on all symbols.
-   [`closeByID`](https://zb-connector.com/docs/commands/closebyid/): Close the position (or positions) with a given positionID.
-   [`closeByLotSize`](https://zb-connector.com/docs/commands/closebylotsize/): Close a given number of lots of one position.
-   [`closeLong`](https://zb-connector.com/docs/commands/closelong/): Close every open buy (long) position, on all symbols.
-   [`closeShort`](https://zb-connector.com/docs/commands/closeshort/): Close every open sell (short) position, on all symbols.
-   [`closeSymbol`](https://zb-connector.com/docs/commands/closesymbol/): Close the open positions on one symbol, long, short or both.

### Change stops and trailing

-   [`moveStops`](https://zb-connector.com/docs/commands/movestops/): Change the stop loss and/or take profit of one position.
-   [`moveStopsBreakeven`](https://zb-connector.com/docs/commands/movestopsbreakeven/): Move the stop loss of one position to its entry price, with an optional offset.
-   [`setTrailingStop`](https://zb-connector.com/docs/commands/settrailingstop/): Attach a trailing stop to one position.

### Accepted, not documented yet

The EA also runs the commands below. They have no reference page yet, so the webhook checks only that the action name is known and does not check their fields.

`hedge`, `placePendingOrder`, `cancelPendingOrder`, `conditionalOrder`, `cancelConditionalOrder`, `batch`, `setEAStatus`, `getEAStatus`, `setSafeguardConfig`, `resetSafeguard`, `getAccountInfo`, `getPositions`, `getStats`

## Related tasks

-   [Create a TradingView alert](https://zb-connector.com/docs/tradingview/alert-basics/)
-   [Find where an alert stopped](https://zb-connector.com/docs/troubleshooting/find-where-it-stopped/)
