Skip to main content

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

NameTypeRequiredDescription
symbolSTRINGYESe.g. "BTCUSDT"
sideSTRINGNO"long" / "short" — informational only in the current release
size_usdDECIMALYESNotional USD value the trade would open (positive)
leverageINTYESLeverage (≥ 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

FieldMeaning
current_uni_mmruniMMR before the hypothetical trade
simulated_uni_mmruniMMR after the hypothetical fill at mark price
new_initial_marginsize_usd / leverage
new_maint_marginTier-aware MM contribution of the new position
available_aftertotal_equity − (current_initial_margin + new_initial_margin)
can_opentrue when all gates pass (see below)
reasonWhen can_open == false, short English string explaining which gate failed

Gating rules

The order would be rejected (can_open == false) if any of:

  • account_status is reduce_only"account in reduce_only mode"
  • account_status is liquidating"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

HTTPCodeMeaning
400INVALID_LEVERAGEleverage < 1
400INVALID_SIZEsize_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())