Skip to main content

Reverse a Position

API Description

This interface allows users to instantly reverse an existing perpetual contract position. By specifying the position ID, the system will close the current position and open a new position in the opposite direction (e.g., long to short or short to long) with the same position size.

Note: Reverse a Position is only available via RESTful API.

Precautions

  1. Position reversal occurs in two steps: The existing position is closed; A new position of the same size is opened in the opposite direction..
  2. After the reversal, the position ID will change.
  3. 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

POST

Endpoint

/v1/perpum/positions/reverse

Frequency Limit

The frequency limit for this interface is 5 requests/s per user ID and 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

ParameterMandatoryTypeDescription
idtrueLongPosition ID

Response Parameters

ParameterTypeDescription
dataLongOrder ID

Request Example

The following Python code shows how to use the one-click position reversal.

Note: For a complete code example, please refer to Introduction > Authentication & Code Snippet > Futures > RESTful Private Interface.

params = { "id": "2435521222632013958"}

api_url = "/v1/perpum/positions/reverse"
method = "POST"
response_code, response_data = FuturesRestfulPrivate(params, api_url, method, sec_key, api_key) # 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': '33308749862574458'}, 'msg': ''}