Margin Type
Description
Query or change the margin type for the caller (cross / isolated).
ZTDX fapi runs in cross margin only
The matching engine and unified-margin paths in the /fapi/* (HMAC) namespace only support cross margin. GET always returns marginType=CROSSED. POST accepts marginType=CROSSED (idempotent), and rejects marginType=ISOLATED with -4046. For genuine isolated-mode bookkeeping, use the JWT-authenticated POST /api/v1/account/margin-mode (see Unified Margin docs).
HTTP Request
- Query: GET
/fapi/v1/marginType(HMAC SHA256) - Change: POST
/fapi/v1/marginType(HMAC SHA256)
Weight
1
GET Request Parameters
| Name | Type | Required | Description |
|---|---|---|---|
| symbol | STRING | NO | Trading pair. If omitted, the response omits the symbol field. |
| recvWindow | LONG | NO | See Endpoint Security Type |
| timestamp | LONG | YES | Timestamp |
POST Request Parameters
| Name | Type | Required | Description |
|---|---|---|---|
| symbol | STRING | YES | Trading pair |
| marginType | STRING | YES | CROSSED (idempotent) or ISOLATED (rejected with -4046). Case-insensitive; CROSS is also accepted. |
| recvWindow | LONG | NO | See Endpoint Security Type |
| timestamp | LONG | YES | Timestamp |
Response Example (GET)
{
"symbol": "BTCUSDT",
"marginType": "CROSSED"
}
Response Example (POST, CROSSED)
{
"code": 200,
"msg": "success"
}
Errors
| Code | Message | Cause |
|---|---|---|
-4046 | Isolated margin is not supported on the developer fapi. ... | marginType=ISOLATED. |
-1128 | Invalid marginType '<value>'. Expected CROSSED or ISOLATED. | Any other value. |
Code Examples
curl (query)
API_KEY="your_api_key"
API_SECRET="your_api_secret"
TIMESTAMP=$(date +%s%3N)
QUERY_STRING="symbol=BTCUSDT×tamp=${TIMESTAMP}"
SIGNATURE=$(echo -n "${QUERY_STRING}" | openssl dgst -sha256 -hmac "${API_SECRET}" | awk '{print $2}')
curl -s -H "X-MBX-APIKEY: ${API_KEY}" \
"https://api.ztdx.io/fapi/v1/marginType?${QUERY_STRING}&signature=${SIGNATURE}"
Python
import time, hmac, hashlib, requests
API_KEY = "your_api_key"
API_SECRET = "your_api_secret"
BASE_URL = "https://api.ztdx.io"
def sign(qs: str) -> str:
return hmac.new(API_SECRET.encode(), qs.encode(), hashlib.sha256).hexdigest()
# Query margin type
ts = int(time.time() * 1000)
qs = f"symbol=BTCUSDT×tamp={ts}"
r = requests.get(
f"{BASE_URL}/fapi/v1/marginType?{qs}&signature={sign(qs)}",
headers={"X-MBX-APIKEY": API_KEY},
)
print(r.json()) # {"symbol":"BTCUSDT","marginType":"CROSSED"}
# Change margin type (CROSSED is idempotent)
import json
ts = int(time.time() * 1000)
body = json.dumps({"symbol": "BTCUSDT", "marginType": "CROSSED"}, separators=(",", ":"))
qs = f"timestamp={ts}"
r = requests.post(
f"{BASE_URL}/fapi/v1/marginType?{qs}&signature={sign(qs + body)}",
data=body,
headers={"X-MBX-APIKEY": API_KEY, "Content-Type": "application/json"},
)
print(r.json()) # {"code":200,"msg":"success"}