Flatten Positions

The FLATTEN positions command is very powerful. It provides the option to flatten all positions across all accounts, a specific position for a particular instrument in a certain direction in one account, or anything in between.

The FLATTEN command accepts several parameters:

  • account

  • instrument

  • market_position (long, short)

  • nothing

The parameters act as filters, searching for positions that match the criteria to be flattened.

Most importantly, if you execute command=FLATTEN; without any other filters, it is similar to the FLATTENEVERYTHING command. All positions will be closed. The only difference is FLATTENEVERYTHING will close all positions and all orders across all accounts.

If FLATTEN is executed with both an account and an instrument it will be equivalent to a generic CLOSEPOSITION command.

Advanced Usage

If no account is specified, but an instrument and/or market_position is provided, FLATTEN will exit all positions across all accounts that match that criteria.

Example Payloads

Flatten all MES 09-25 positions in Sim101 account (CLOSEPOSITION equivalent):

key=your-secret-key;
command=FLATTEN;
account=Sim101;
instrument=MES 09-25;

Flatten all positions in the Sim101 account:

key=your-secret-key;
command=FLATTEN;
account=sim101;

Flatten all short positions in Sim101:

key=your-secret-key;
command=FLATTEN;
account=sim101;
market_position=short;

Flatten all long positions across all NT8 accounts:

key=your-secret-key;
command=FLATTEN;
market_position=short;

Flatten all MNQ 09-25 positions across all NT8 accounts:

key=your-secret-key;
command=FLATTEN;
instrument=MNQ 09-25;

Flatten all positions in all accounts:

key=your-secret-key;
command=FLATTEN;

Last updated