Skip to main content

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)

GET Request Parameters

NameTypeRequiredDescription
symbolSTRINGNOTrading pair. If omitted, the symbol field in the response is null.
recvWindowLONGNOIgnored — the server enforces a fixed ±60 second timestamp window regardless of this value.
timestampLONGYESTimestamp

POST Request Parameters

NameTypeRequiredDescription
symbolSTRINGYESTrading pair
marginTypeSTRINGYESCROSSED (idempotent) or ISOLATED (rejected with -4046). Case-insensitive; CROSS is also accepted.
recvWindowLONGNOIgnored — the server enforces a fixed ±60 second timestamp window regardless of this value.
timestampLONGYESTimestamp

Response Example (GET)

{
"symbol": "BTCUSDT",
"marginType": "CROSSED"
}

Response Example (POST, CROSSED)

{
"code": 200,
"msg": "success"
}

Errors

CodeMessageCause
-4046Isolated margin is not supported on the developer fapi. ...marginType=ISOLATED.
-1128Invalid 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&timestamp=${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.prex.world/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.prex.world"

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&timestamp={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"}