Switch Margin Mode
Switch the authenticated user between isolated (per-position margin)
and unified (portfolio margin) modes.
HTTP Request
POST /api/v1/account/margin-mode (HMAC SHA256)
Preconditions
| Target | Required state |
|---|---|
unified | No pending / open / partially-filled orders; new uniMMR (if positions exist) must be ≥ 1.10 — otherwise the switch is rolled back and the call returns 400 UNI_MMR_TOO_LOW |
isolated | No pending / open / partially-filled orders AND no open positions |
Request Body
| Name | Type | Required | Description |
|---|---|---|---|
| margin_mode | STRING | YES | "isolated" or "unified" |
Response Example
{
"success": true,
"margin_mode": "unified",
"uni_mmr": null,
"available_balance": "0"
}
Error Codes
| HTTP | Code | Meaning |
|---|---|---|
| 400 | INVALID_MARGIN_MODE | margin_mode is not "isolated" / "unified" |
| 400 | HAS_OPEN_ORDERS | User has non-terminal orders — cancel them first |
| 400 | HAS_OPEN_POSITIONS | Switching to isolated while positions are still open |
| 400 | UNI_MMR_TOO_LOW | uniMMR would be below 1.10 after switching to unified — switch rolled back |
Code Examples
curl
API_KEY="your_api_key"
API_SECRET="your_api_secret"
TIMESTAMP=$(date +%s%3N)
BODY='{"margin_mode":"unified"}'
PAYLOAD="timestamp=${TIMESTAMP}${BODY}"
SIGNATURE=$(echo -n "${PAYLOAD}" | openssl dgst -sha256 -hmac "${API_SECRET}" | awk '{print $2}')
curl -s -X POST \
-H "X-MBX-APIKEY: ${API_KEY}" \
-H "Content-Type: application/json" \
--data "${BODY}" \
"https://api.ztdx.io/api/v1/account/margin-mode?timestamp=${TIMESTAMP}&signature=${SIGNATURE}"
Python
import time, hmac, hashlib, json, requests
API_KEY = "your_api_key"
API_SECRET = "your_api_secret"
ts = int(time.time() * 1000)
body = json.dumps({"margin_mode": "unified"}, separators=(",", ":"))
payload = f"timestamp={ts}{body}"
sig = hmac.new(API_SECRET.encode(), payload.encode(), hashlib.sha256).hexdigest()
r = requests.post(
f"https://api.ztdx.io/api/v1/account/margin-mode?timestamp={ts}&signature={sig}",
headers={"X-MBX-APIKEY": API_KEY, "Content-Type": "application/json"},
data=body,
)
print(r.json())