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

# transferMdToShareGroup: Move Funds into a Share Group

> Transfer margin from a market deployer cross margin pool into a portfolio share group pool to fund PORTFOLIO mode margin sharing across contracts.

In PORTFOLIO mode, contracts within a share group draw margin from a shared pool rather than individual per-MD balances. Use `transferMdToShareGroup` to fund that pool by moving collateral from a market deployer's cross margin pool into a specific share group. The transfer is subject to the same withdrawable amount constraints that apply to the source market deployer — position IM and order-frozen margin reduce how much you can move.

<Note>
  Your account must be in **PORTFOLIO mode** to use share groups. Switch modes first with [`setMarginShareType`](/exchange/set-margin-share-type).
</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": "transferMdToShareGroup",
    "marketDeployerId": 1,
    "groupId": 3,
    "coinId": 1,
    "amount": "1000"
  },
  "signature": { "r": "0x...", "s": "0x...", "v": 28 },
  "nonce": 1778859200000
}
```

### Action parameters

<ParamField body="marketDeployerId" type="int32" required>
  The ID of the source market deployer. Funds are deducted from this deployer's cross margin pool and are subject to its withdrawable amount limit.
</ParamField>

<ParamField body="groupId" type="int32" required>
  The ID of the target share group. Funds are credited to this group's shared 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 on the source deployer. Decimals are not accepted — use the coin's smallest unit.
</ParamField>

## Response

A successful transfer returns the updated balances for both the source market deployer and the destination share group.

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

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

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

<ResponseField name="fromBalanceAfter" type="int64">
  The cross margin balance of the source market deployer after the transfer.
</ResponseField>

<ResponseField name="toBalanceAfter" type="int64">
  The share group's margin pool balance 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 on the MD** — position IM and frozen order margin on the source deployer 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": "account is not in portfolio margin mode"
    }
  }
}
```

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