Simulate New Order (Pre-trade Risk)
Preview what opening a new position would do to the caller's
uniMMR. Useful for front-ends that want to surface "safe leverage" or
"this trade will put you into margin-call territory" UX before the
user clicks submit.
This endpoint is a pure calculation — no order is placed, no state changes.
HTTP Request
POST /api/v1/unified/risk/simulate (HMAC SHA256)
Request Body
| Name | Type | Required | Description |
|---|---|---|---|
| symbol | STRING | YES | e.g. "BTCUSDT" |
| side | STRING | NO | "long" / "short" — informational only in the current release |
| size_usd | DECIMAL | YES | Notional USD value the trade would open (positive) |
| leverage | INT | YES | Leverage (≥ 1, ≤ symbol max) |
Response Example
{
"current_uni_mmr": "3.50",
"simulated_uni_mmr": "2.80",
"new_initial_margin": "2500.00",
"new_maint_margin": "250.000000",
"available_after": "42500.00",
"can_open": true,
"reason": null
}
Field semantics
| Field | Meaning |
|---|---|
current_uni_mmr | uniMMR before the hypothetical trade |
simulated_uni_mmr | uniMMR after the hypothetical fill at mark price |
new_initial_margin | size_usd / leverage |
new_maint_margin | Tier-aware MM contribution of the new position |
available_after | total_equity − (current_initial_margin + new_initial_margin) |
can_open | true when all gates pass (see below) |
reason | When can_open == false, short English string explaining which gate failed |
Gating rules
The order would be rejected (can_open == false) if any of:
account_statusisreduce_only→"account in reduce_only mode"account_statusisliquidating→"account is liquidating"available_after < 0→"insufficient available balance after opening"simulated_uni_mmr < 1.10→"simulated uniMMR would fall below 1.10"
Error Codes
| HTTP | Code | Meaning |
|---|---|---|
| 400 | INVALID_LEVERAGE | leverage < 1 |
| 400 | INVALID_SIZE | size_usd <= 0 |
Code Examples
curl
API_KEY="your_api_key"
API_SECRET="your_api_secret"
TIMESTAMP=$(date +%s%3N)
BODY='{"symbol":"BTCUSDT","side":"long","size_usd":"5000","leverage":10}'
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/unified/risk/simulate?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({"symbol": "BTCUSDT", "size_usd": "5000", "leverage": 10},
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/unified/risk/simulate?timestamp={ts}&signature={sig}",
headers={"X-MBX-APIKEY": API_KEY, "Content-Type": "application/json"},
data=body,
)
print(r.json())