Skip to main content

Close Position By IDs

Close Position By IDs

Close specific positions by specified position ID list, supporting spot, coin-margined contracts, and USDT-margined contracts

Request frequency limit: 1/1s

Request URL

POST /deepcoin/trade/close-position-by-ids

Request Parameters

Field NameRequiredTypeDescription
productGrouptruestringProduct group
Spot: Spot
Coin-margined: Swap
USDT-margined: SwapU
instIdtruestringProduct ID
positionIdstrue[]stringPosition ID list, must contain at least one ID

Request Example

// Close specified spot positions
{
"productGroup": "Spot",
"instId": "BTC-USDT",
"positionIds": ["pos123", "pos456"]
}

// Close specified coin-margined contract positions
{
"productGroup": "Swap",
"instId": "BTC-USD-SWAP",
"positionIds": ["pos789", "pos012", "pos345"]
}

// Close specified USDT-margined contract positions
{
"productGroup": "SwapU",
"instId": "BTC-USDT-SWAP",
"positionIds": ["pos678"]
}

// Close multiple positions
{
"productGroup": "SwapU",
"instId": "ETH-USDT-SWAP",
"positionIds": [
"1001063717138767",
"1001063717138768",
"1001063717138769",
"1001063717138770"
]
}

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 specified 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": 51404,
"errorMsg": "Position does not exist"
}
]
}
}

// All failures response
{
"code": "0",
"msg": "",
"data": {
"errorList": [
{
"memberId": "10001",
"accountId": "100001234",
"tradeUnitId": "TU001",
"instId": "BTC-USDT-SWAP",
"posiDirection": "long",
"errorCode": 51404,
"errorMsg": "Position does not exist"
},
{
"memberId": "10001",
"accountId": "100001234",
"tradeUnitId": "TU002",
"instId": "BTC-USDT-SWAP",
"posiDirection": "short",
"errorCode": 51404,
"errorMsg": "Position does not exist"
}
]
}
}

Description

Functionality

  • Close specific positions by specified position ID list
  • Supports spot (Spot), coin-margined contracts (Swap), and USDT-margined contracts (SwapU)
  • Can close multiple specified positions at once
  • Uses concurrent processing to improve efficiency

Processing Logic

  1. Internally calls the same doClosePositionInternal method as batch close position
  2. Filters through positionIds parameter to only close positions with specified IDs
  3. Processes multiple position closures concurrently
  4. Collects all position closure failure error information

Notes

  • positionIds must contain at least one position ID
  • Only positions specified in the list will be closed, other positions will not be affected
  • An empty error list indicates all specified positions were closed successfully
  • Failed closures of some positions will not affect the closure operations of other positions
  • If a position ID does not exist or has already been closed, corresponding error information will be returned in the error list