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

# setMarginShareType: Switch Account Margin Share Mode

> Switch your account between UNIFIED mode (isolated per-MD margin) and PORTFOLIO mode (shared group margin pool) to control how margin is allocated.

Upside DEX supports two margin sharing modes that determine how margin is allocated across your contracts. Use `setMarginShareType` to switch between them. The mode you choose affects every market deployer in your account, so ensure you have no open positions or active orders before switching — the exchange will reject the request otherwise.

* **UNIFIED (0)** — the default mode. Each market deployer maintains its own isolated margin pool. A loss in one MD cannot draw down margin from another.
* **PORTFOLIO (1)** — opt-in portfolio margin mode. Contracts that belong to the same share group draw from a single shared margin pool, enabling cross-margining. This can significantly reduce your overall margin requirements when you hold offsetting positions.

<Warning>
  You must have **no open positions and no active orders** before changing your margin share type. Close all positions and cancel all orders first, then resubmit this request.
</Warning>

## Endpoint

```
POST https://dev.upsidemax.xyz/exchange
```

## Request

The example below switches your account to PORTFOLIO mode. To revert to UNIFIED, set `marginShareType` to `0`.

```json theme={"system"}
{
  "action": {
    "type": "setMarginShareType",
    "marginShareType": 1
  },
  "signature": { "r": "0x...", "s": "0x...", "v": 28 },
  "nonce": 1778859100000
}
```

### Action parameters

<ParamField body="marginShareType" type="int8" required>
  The margin mode to apply to your account:

  * `0` — **UNIFIED**: each market deployer has its own isolated margin pool (default).
  * `1` — **PORTFOLIO**: contracts within a share group share one margin pool.

  Any value other than `0` or `1` is rejected.
</ParamField>

## Response

On success, the exchange returns a governance acknowledgement. The `entityId` is always `0` and serves only as a confirmation token.

```json theme={"system"}
{
  "status": "ok",
  "response": {
    "type": "governance",
    "data": {
      "entityId": 0
    }
  }
}
```

<ResponseField name="entityId" type="int32">
  Always `0` on a successful `setMarginShareType` call. No further data is returned.
</ResponseField>

## Errors

If the request cannot be fulfilled, the exchange still returns **HTTP 200** with `status: "ok"` — the rejection is reported inside `response.data`, where a server-assigned integer `errorCode` and a human-readable `errorMessage` are populated while the numeric data fields are set to `0`. Common causes include:

* **Open positions exist** — all positions must be closed before switching modes.
* **Active orders exist** — all orders must be cancelled before switching modes.
* **Invalid `marginShareType` value** — only `0` and `1` are valid.

```json theme={"system"}
{
  "status": "ok",
  "response": {
    "type": "governance",
    "data": {
      "entityId": 0,
      "errorCode": 1,
      "errorMessage": "cannot change margin share type while open positions exist"
    }
  }
}
```

<Note>
  After switching to PORTFOLIO mode, use [`transferMdToShareGroup`](/exchange/transfer-md-to-share-group) or [`lockIntoShareGroup`](/exchange/lock-into-share-group) to fund your share groups before placing orders.
</Note>
