# Require Market Position

The flag `require_market_position` is available to any command with both an `account` and `instrument` field. It blocks and prevents the signal from going through unless the NT8 market position is:

* flat
* short
* long
* flat or long
* short or long
* long or short

Require market position is available to any of the following command types:

* PLACE
* FLATPLACE
* CANCELREPLACE
* CANCELORDERS
* CLOSEPOSITION
* REVERSEPOSITION
* FLATTEN

### Checking Multiple Market Positions

In addition to the standard long, short, flat market positions, we've included the ability to check for 2 of the 3 conditions. That is, if any one of 2 conditions are true, the signal won't be blocked.

The use case here is if you want to add to a position in a certain direction, but only if you're already long or flat in that direction. For example, if you are long +3 contracts and you want to add +1 contracts, you want to ensure you are either long or flat in that direction already. Otherwise, if you're short, you would only be making your position "less short" by closing 1 contract.&#x20;

To check for the "long or flat" conditions, separate the values with a comma. CSV values represent an "or" condition between them: "flat or long", "long or short", etc. They can be in any order: "flat,long", "long,flat", etc.&#x20;

An example command would be:

```
key=your-secret-key;
command=PLACE;
account=sim101;
instrument=ES 09-25;
action=BUY;
qty=1;
order_type=MARKET;
tif=DAY;
require_market_position=long,flat;
```

which translates to buy +1 ES 09-25 at market if and only if a position already exists in ES 09-25 that is flat or long. If a short position is open, block the signal.

### Example Payloads

In the simplest case, a `PLACE` command with `require_market_position=flat;` for account "sim101" and instrument "ES 09-25" will not be processed unless there's no preexisting position in ES 09-25 under account sim101. The position _must be_ flat for the order to proceed:

> key=your-secret-key;\
> command=PLACE;\
> account=sim101;\
> instrument=ES 09-25;\
> action=BUY;\
> qty=1;\
> order\_type=MARKET;\
> TIF=DAY;\
> **require\_market\_position=flat;**

Let's say you have multiple alert types in play: Long Entry, Long Exit, Short Entry, Short Exit. You don't want to process the "Short Exit" signal to close if there's a long position already in play. In this instance, you could require the alert to be processed if and only if the current market position is short:

> key=your-secret-key;\
> command=CLOSEPOSITION;\
> account=sim101;\
> **require\_market\_position=short;**

Similar to our example in the [Multiple Market Positions](#checking-multiple-market-positions) section above, if we want to sell short an "ES 09-25" contract if and only if the exist position in the "sim101" account is flat or short:

> key=your-secret-key; \
> command=PLACE; \
> account=sim101; \
> instrument=ES 09-25;\
> action=SELL; \
> qty=1; \
> order\_type=MARKET; \
> tif=DAY; \
> **require\_market\_position=flat,short;**
