> ## Documentation Index
> Fetch the complete documentation index at: https://public-perps-docs.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Position Margin

> Add or remove margin on isolated positions

Adjust the margin on an isolated position via `PerpsClient.updatePositionMargin`. The registered provider plugin authorizes and submits the action according to its descriptor.

<Info>
  Position-margin support is market-specific. Read `market.positionMarginAdjustment` or use the helper predicates below instead of assuming every provider supports both directions.
</Info>

## Capability and Constraints

`PositionMarginAdjustment` has three values:

| Value            | Meaning                                      |
| ---------------- | -------------------------------------------- |
| `NONE`           | Individual position margin cannot be changed |
| `ADD_ONLY`       | Margin can be added but not removed          |
| `ADD_AND_REMOVE` | Margin can be added and removed              |

```typescript theme={null}
import {
  positionSupportsMarginAdjustment,
  positionSupportsMarginRemoval,
  removableIsolatedMargin,
} from '@lifi/perps-sdk';

if (positionSupportsMarginAdjustment(position)) {
  const constraints = perps.getPositionMarginConstraints(position);
  const removable = constraints && positionSupportsMarginRemoval(position)
    ? removableIsolatedMargin({ position, constraints })
    : '0';
}
```

`getPositionMarginConstraints(position)` returns the provider-owned `{ minimumMarginRequirement, amountIncrement }` decimal strings, or `undefined` when the position has no individual margin adjustment. `removableIsolatedMargin` accounts for unrealized PnL and snaps down to the accepted increment.

***

## updatePositionMargin

```typescript theme={null}
const result = await perps.updatePositionMargin({
  provider: 'hyperliquid',
  address: userAddress,
  market: { marketId: 'BTC', categoryId: 'hyperliquid' },
  action: 'add',
  amount: '500.00',
});
```

Pass `action: 'remove'` (with a positive `amount`) to withdraw margin from the position without changing its size.

**API Reference:** [POST /createAction · /executeAction](/api-reference/actions)
