> ## 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.

# transferShareGroupToMd: Move Funds from Share Group

> Transfer available margin from a portfolio share group pool back into a market deployer cross margin pool to rebalance between margin modes.

When you need to rebalance funds between your PORTFOLIO share groups and per-MD cross margin pools, use `transferShareGroupToMd`. This action moves collateral from a share group's shared margin pool back into a specific market deployer's cross margin pool. The transfer is constrained by the withdrawable amount available in the source share group — meaning position IM and order-frozen margin held against contracts in that group reduce how much you can move.

<Note>
  Your account must be in **PORTFOLIO mode** to interact with share groups. If you want to revert fully to UNIFIED mode, first drain all share groups back to their market deployers, then call [`setMarginShareType`](/exchange/set-margin-share-type) with `marginShareType: 0`.
</Note>

## Endpoint

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

## Request

Every request must carry an ECDSA signature and a nonce to prevent replay attacks.

```json theme={"system"}
{
  "action": {
    "type": "transferShareGroupToMd",
    "groupId": 3,
    "marketDeployerId": 1,
    "coinId": 1,
    "amount": "1000"
  },
  "signature": { "r": "0x...", "s": "0x...", "v": 28 },
  "nonce": 1778859300000
}
```

### Action parameters

<ParamField body="groupId" type="int32" required>
  The ID of the source share group. Funds are deducted from this group's shared margin pool, subject to its withdrawable amount limit.
</ParamField>

<ParamField body="marketDeployerId" type="int32" required>
  The ID of the destination market deployer. Funds are credited to this deployer's cross margin pool.
</ParamField>

<ParamField body="coinId" type="int32" required>
  The coin or currency ID to transfer.
</ParamField>

<ParamField body="amount" type="string" required>
  The amount to transfer, expressed as a raw integer string (e.g. `"1000"`). Must be greater than zero and must not exceed the withdrawable amount available in the source share group. Decimals are not accepted — use the coin's smallest unit.
</ParamField>

## Response

A successful transfer returns the updated balances for both the source share group and the destination market deployer. The response type is `shareGroupFund`, consistent with other share group fund operations.

```json theme={"system"}
{
  "status": "ok",
  "response": {
    "type": "shareGroupFund",
    "data": {
      "coinId": 1,
      "amount": 1000,
      "fromBalanceAfter": 0,
      "toBalanceAfter": 5000
    }
  }
}
```

<ResponseField name="coinId" type="int32">
  The coin ID that was transferred.
</ResponseField>

<ResponseField name="amount" type="int64">
  The amount moved from the share group into the market deployer.
</ResponseField>

<ResponseField name="fromBalanceAfter" type="int64">
  The share group's margin pool balance after the transfer.
</ResponseField>

<ResponseField name="toBalanceAfter" type="int64">
  The cross margin balance of the destination market deployer after the transfer.
</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 amount and balance fields are set to `0`. Common causes include:

* **Amount exceeds withdrawable balance in the share group** — position IM and frozen order margin on contracts within the group constrain how much can be moved.
* **Account not in PORTFOLIO mode** — share groups are only active when your margin share type is `1`.
* **Invalid `groupId`** — the specified share group must exist and be accessible to your account.
* **Amount ≤ 0** — the `amount` field must be a positive integer string.

```json theme={"system"}
{
  "status": "ok",
  "response": {
    "type": "shareGroupFund",
    "data": {
      "coinId": 0,
      "amount": 0,
      "fromBalanceAfter": 0,
      "toBalanceAfter": 0,
      "errorCode": 1,
      "errorMessage": "requested amount exceeds withdrawable balance in share group"
    }
  }
}
```

<Tip>
  To move funds in the opposite direction — from a market deployer into a share group — use [`transferMdToShareGroup`](/exchange/transfer-md-to-share-group). To withdraw from a share group directly to your chain-level balance, use [`unlockFromShareGroup`](/exchange/unlock-from-share-group).
</Tip>
