Change Leverage
Description
Change the leverage for a specific trading pair.
HTTP Request
POST /fapi/v1/leverage (HMAC SHA256)
Weight
1
Request Parameters
| Name | Type | Required | Description |
|---|---|---|---|
| symbol | STRING | YES | Trading pair |
| leverage | INT or STRING | YES | Target leverage. Must lie within the symbol's [min_leverage, max_leverage] band; see Leverage Brackets & Position Limits. Accepted as a numeric string ("20") or integer (20). A breach returns -4028. |
| recvWindow | LONG | NO | See Endpoint Security Type |
| timestamp | LONG | YES | Timestamp |
Response Example
{
"leverage": 20,
"maxNotionalValue": "1000000",
"symbol": "BTCUSDT"
}
The leverage value is persisted per (user, symbol). Subsequent
orders on this pair that do not carry an explicit leverage field
will use the persisted value. Sending a new POST /fapi/v1/leverage
overwrites it.
maxNotionalValue is the per-symbol position cap (max_position_size_usd)
from the venue's market configuration, surfaced unchanged from
Leverage Brackets & Position Limits. Lowering
leverage with an open position does not retroactively re-margin or
re-price the existing position — only subsequent orders are affected.
Code Examples
cURL
API_KEY="your_api_key"
API_SECRET="your_api_secret"
TIMESTAMP=$(date +%s%3N)
QUERY_STRING="symbol=BTCUSDT&leverage=20×tamp=${TIMESTAMP}"
SIGNATURE=$(echo -n "${QUERY_STRING}" | openssl dgst -sha256 -hmac "${API_SECRET}" | awk '{print $2}')
curl -s -X POST \
-H "X-MBX-APIKEY: ${API_KEY}" \
"https://api-sepolia.ztdx.io/fapi/v1/leverage?${QUERY_STRING}&signature=${SIGNATURE}"
Python
import time, hmac, hashlib, requests, json
API_KEY = "your_api_key"
API_SECRET = "your_api_secret"
BASE_URL = "https://api.ztdx.io"
def sign(msg: str) -> str:
return hmac.new(API_SECRET.encode(), msg.encode(), hashlib.sha256).hexdigest()
def signed_post(path, body={}):
ts = int(time.time() * 1000)
qs = f"timestamp={ts}"
body_str = json.dumps(body, separators=(',', ':'))
sig = sign(qs + body_str)
return requests.post(
f"{BASE_URL}{path}?timestamp={ts}&signature={sig}",
data=body_str,
headers={"X-MBX-APIKEY": API_KEY, "Content-Type": "application/json"},
)
# Change leverage to 20x for BTCUSDT
resp = signed_post("/fapi/v1/leverage", body={
"symbol": "BTCUSDT",
"leverage": 20,
})
print(resp.json())
# {"leverage": 20, "maxNotionalValue": "10000000.0000", "symbol": "BTCUSDT"}