Close a Position
API Description
This interface allows users to close an open futures position (filled order) either partially or fully. Users can specify the position ID and choose to close it based on either a fixed contract size or a percentage of the total position. An optional order price can also be specified to close the position at a certain price.
Note: Close a Position is only available via RESTful API.
Precautions
- Typically, a position is closed by placing an identical order in the opposite direction. However, this approach does not apply on CoinW. Placing an order in the opposite direction will open a new position instead of closing the original one, resulting in two active positions. To properly close a position, please use this dedicated interface.
- During the funding period, operations related to transaction such as placing orders or closing positions are not permitted. Attempting these actions will result in an error response. The funding process typically takes 30 to 40 seconds. It is recommended to wait at least 1 minute before retrying transaction related operations. For the exact funding fee schedule, please refer to the official webpage.
- While the platform displays positions from user's own orders, copy trading, and strategy square uniformly, the OpenAPI only supports operations (such as closing positions or canceling orders) for user's own orders. For positions generated by copy trading and strategy square, API operations are not permitted, and users should use the platform's corresponding functions.
Authentication
This is a private interface and requires authentication. For details on using the RESTful API, refer to Introduction > Authentication & Code Snippet > Futures > RESTful Private Interface.
Request Method
DELETE
Endpoint
Frequency Limit
The frequency limit for this interface is 30 requests/second per user ID and 100000 requests/second per IP. In addition to this per-interface limit, a global rate limit is also enforced.
For detailed information on Global rate limits and API Rate Limiting Policy, please refer to the "Frequency Limit" section at click here
Request Parameters
| Parameter | Mandatory | Type | Description |
|---|---|---|---|
| id | true | Long | Position ID |
| positionType | false | String | Specifies the type of closing order: plan: close the position at a specified price. execute: close the position at market price. Note: If not specified, the position will be closed using market price (execute) by default. |
| closeNum | false | BigDecimal | Number of contracts to close. i.e., 2 means closing 2 contracts. Note: This parameter is mutually exclusive with closeRate; one of them must be provided. |
| closeRate | false | BigDecimal | Closing ratio, with a valid range from 0 to 1.Example: If set to 0.5, 50% of the position will be closed. Note: This parameter is mutually exclusive with closeNum; one of them must be provided. |
| orderPrice | false | BigDecimal | Specified closing price Note: If specified, the "positionType" must be set to "plan". |
Response Parameters
| Parameter | Type | Description |
|---|---|---|
| data | Long | Order ID |
Request Example
The following Python code shows how to close an open position (filled order) at a specified price.
Note: For a complete code example, please refer to Introduction > Authentication & Code Snippet > Futures > RESTful Private Interface.
params = {
"id": "2435521222632023294",
"positionType" : "plan" ,
# "closeRate": 1,
"closeNum" : 1 ,
"orderPrice" : 86500 ,
}
api_url = "/v1/perpum/positions"
method = "DELETE"
response_code, response_data = FuturesRestfulPrivate(params, api_url, method, sec_key, api_key) # function FuturesRestfulPrivate() is defined in section (Introduction > Authentication & Code Snippet > Futures > RESTful Private Interface)
Note: For a complete Java code example, please refer to Introduction > Authentication & Code Snippet > Futures > RESTful Private Interface.
Response Example
The following is an example response returned by the above Python request:
{'code': 0, 'data': {'value': 33308750217533160}, 'msg': ''}