# Position Count Limit

The position count limit is a risk management feature that allows exchange operators to set a maximum number of positions that each account can hold simultaneously. It is an exchange-wide setting that applies uniformly to all trading accounts. When configured, it restricts the number of distinct instrument positions that any single account can hold at one time.

## How Position Count Limit Works

### Position Counting

The position count limit counts all of the following toward the limit:

- **Active Positions**: Any non-zero position on any instrument
- **Unterminated Orders**: All resting orders, including:
  - Limit orders in the order book
  - Stop orders waiting to be triggered
  - Contingent orders

This comprehensive counting ensures that even orders that haven't yet resulted in positions are accounted for in the limit.

### Order Rejection Criteria

Orders on instruments where the account has no existing *position* or *orders* are rejected if the account is at the limit.

### Allowed Operations

Even when at or over the position count limit, accounts can still:

- **Trade Existing Positions**: Place orders on instruments where the account already has a position or unterminated orders
- **Close Positions**: Use reduce-only or close orders to exit existing positions
- **Modify Existing Orders**: Amend or cancel existing orders

### Closing Positions

When an account closes a position (reduces it to zero and has no unterminated orders on that instrument), the capacity is freed:

- The position count decreases by one
- The account can now open a position on a different instrument
- This allows accounts to rotate between instruments while respecting the limit

### Limit Reduction

If the exchange operator reduces the position count limit downward, accounts that are already over the new limit are grandfathered:

- **Existing Positions Protected**: The account can continue trading its existing positions
- **New Positions Blocked**: The account cannot open positions on new instruments until it falls below the new limit
- **Gradual Compliance**: Accounts naturally come into compliance as they close positions

### Liquidation Account Exception

The liquidation account can receive positions through the liquidation process even if such positions would cause it to exceed the position count limit.

## Reference

### API Endpoints

All position count limit endpoints are part of the Exchange-Wide Controls API and are accessible via the control gateway (port 8181).

#### Set Position Count Limit

Configure the maximum number of positions allowed per account across the entire exchange.

```http
POST /ExchangeWideControls/PositionCountLimit?limit={count}
```

**Parameters**

| Parameter | Type   | Required | Description                                                  |
|-----------|--------|----------|--------------------------------------------------------------|
| limit     | number | Yes      | Maximum number of positions per account (must be positive)   |

**Example**

```bash
curl -X 'POST' \
  'http://control-gateway:8181/ExchangeWideControls/PositionCountLimit?limit=100' \
  -H 'accept: application/json' \
  -d ''
```

This sets the position count limit to 100 positions per account across the entire exchange.

**Response**

Returns confirmation of the position count limit configuration.

#### Get Position Count Limit

Retrieve the current position count limit setting.

```http
GET /ExchangeWideControls/PositionCountLimit
```

**Example**

```bash
curl -X 'GET' \
  'http://control-gateway:8181/ExchangeWideControls/PositionCountLimit' \
  -H 'accept: application/json'
```

**Response**

Returns the current position count limit value, or indicates if no limit is set.

#### Delete Position Count Limit

Remove the position count limit, allowing accounts to hold unlimited positions.

```http
DELETE /ExchangeWideControls/PositionCountLimit
```

**Example**

```bash
curl -X 'DELETE' \
  'http://control-gateway:8181/ExchangeWideControls/PositionCountLimit' \
  -H 'accept: application/json' \
  -d ''
```

**Response**

Returns confirmation that the position count limit has been removed.

## Related Documentation
  - See [Liquidation Account](/docs/maintenance_margin/insurance_fund) for information about the liquidation account's special properties
  - See [Maintenance Margin](/docs/maintenance_margin/) for the overall liquidation workflow
