fetch:
binanceusdm GET https://fapi.binance.com/fapi/v1/positionRisk?timestamp=1635651593751&recvWindow=5000&symbol=BTCUSDT&signature=cbf317bb9ae2569f2d0f8ad2000f6c3922acdb3ef5c9bd9cf62db77dbd92520a
handleRestResponse:
binanceusdm GET https://fapi.binance.com/fapi/v1/positionRisk?timestamp=1635651593751&recvWindow=5000&symbol=BTCUSDT&signature=cbf317bb9ae2569f2d0f8ad2000f6c3922acdb3ef5c9bd9cf62db77dbd92520a 200 OK
Response:
[
{
"symbol": "BTCUSDT",
"positionAmt": "0.001",
"entryPrice": "61788.9",
"markPrice": "61792.09000000",
"unRealizedProfit": "0.00319000",
"liquidationPrice": "8465.58529116",
"leverage": "2",
"maxNotionalValue": "600000000",
"marginType": "cross",
"isolatedMargin": "0.00000000",
"isAutoAddMargin": "false",
"positionSide": "BOTH",
"notional": "61.79209000",
"isolatedWallet": "0",
"updateTime": 1635651734305
}
]
Equation
We can find the cross wallet balance using the position risk endpoint with this equation:
walletBalance = (liquidationPrice * (±1 + maintenanceMarginPercentage) ± entryPrice) * positionAmt
short
first ± becomes + and the second ± becomes -
long
first ± becomes - and the second ± becomes +
Example
cross walletBalance = (8465.58529116 * (-1 + 0.004) + 61788.9) * 0.001 = 53.35 USDT/BUSD
COINM API Issue
short 4 contracts
{
"symbol": "BTCUSD_PERP",
"positionAmt": "-4",
"entryPrice": "61765.49999957",
"markPrice": "61765.50000000",
"unRealizedProfit": "0.00000000",
"liquidationPrice": "0", <---
"leverage": "2",
"maxQty": "1500",
"marginType": "cross",
"isolatedMargin": "0.00000000",
"isAutoAddMargin": "false",
"positionSide": "BOTH",
"notionalValue": "-0.00647610",
"isolatedWallet": "0",
"updateTime": "1635653044474"
}
short 5 contracts
{
"symbol": "BTCUSD_PERP",
"positionAmt": "-5",
"entryPrice": "61755.59364860",
"markPrice": "61716.00000000",
"unRealizedProfit": "0.00000519",
"liquidationPrice": "397179.04831492",
"leverage": "2",
"maxQty": "1500",
"marginType": "cross",
"isolatedMargin": "0.00000000",
"isAutoAddMargin": "false",
"positionSide": "BOTH",
"notionalValue": "-0.00810162",
"isolatedWallet": "0",
"updateTime": "1635653210653"
}
Relevant endpoints
/dapi/v1/positionRisk
/fapi/v2/positionRisk (this endpoint does not return liquidationPrice: 0 as frequently or at all)
Problem
If the API responds with liquidationPrice: 0
when the liquidationPrice is too high or too low we cannot find the cross wallet balance.