Skip to main content

Batch Close Position

Batch Close Position

Batch close all positions for a specified product, supporting spot, coin-margined contracts, and USDT-margined contracts

Request frequency limit: 1/1s

Request URL

POST /deepcoin/trade/batch-close-position

Request Parameters

Field NameRequiredTypeDescription
productGrouptruestringProduct group
Spot: Spot
Coin-margined: Swap
USDT-margined: SwapU
instIdtruestringProduct ID

Request Example

// Batch close spot positions
{
"productGroup": "Spot",
"instId": "BTC-USDT"
}

// Batch close coin-margined contract positions
{
"productGroup": "Swap",
"instId": "BTC-USD-SWAP"
}

// Batch close USDT-margined contract positions
{
"productGroup": "SwapU",
"instId": "BTC-USDT-SWAP"
}

Response Parameters

Field NameTypeDescription
errorListarrayError list containing detailed information of failed closures

ClosePositionErrorItem Structure in errorList

Field NameTypeDescription
memberIdstringMember ID
accountIdstringAccount ID
tradeUnitIdstringTrade unit ID
instIdstringProduct ID
posiDirectionstringPosition direction
errorCodeintError code
errorMsgstringError message

Response Example

// Successful response (all positions closed successfully)
{
"code": "0",
"msg": "",
"data": {
"errorList": []
}
}

// Partial failure response
{
"code": "0",
"msg": "",
"data": {
"errorList": [
{
"memberId": "10001",
"accountId": "100001234",
"tradeUnitId": "TU001",
"instId": "BTC-USDT-SWAP",
"posiDirection": "long",
"errorCode": 51020,
"errorMsg": "Insufficient position"
},
{
"memberId": "10001",
"accountId": "100001234",
"tradeUnitId": "TU002",
"instId": "BTC-USDT-SWAP",
"posiDirection": "short",
"errorCode": 51008,
"errorMsg": "Order does not exist"
}
]
}
}

Description

Functionality

  • Batch close all positions for a specified product
  • Supports spot (Spot), coin-margined contracts (Swap), and USDT-margined contracts (SwapU)
  • Uses concurrent processing to improve efficiency
  • Returns an error list containing detailed information about all failed closures

Processing Logic

  1. Calls different services (spot/contracts) based on productGroup
  2. Processes multiple position closures concurrently
  3. Collects all position closure failure error information
  4. Even if some positions fail to close, successful positions will still be closed

Notes

  • This API will close all positions for the specified product, please use with caution
  • An empty error list indicates all positions were closed successfully
  • Failed closures of some positions will not affect the closure operations of other positions