Close Position
Close an existing position or modify its take profit/stop loss orders
Overview
The Close Position endpoint allows you to close an existing position (partially or fully) or modify its take profit and stop loss orders. You can specify the amount to close and set price limits for the closing transaction.
Request Body
ID of the position to close or modify
Optional. Amount to decrease the position by. If not provided, closes entire position
Optional. Maximum (for longs) or minimum (for shorts) allowed price for closing
Optional. New take profit price. Set to modify existing take profit order
Optional. New stop loss price. Set to modify existing stop loss order
Required if takeProfit is set. Percentage to close at take profit (in basis points, 10000 = 100%)
Required if stopLoss is set. Percentage to close at stop loss (in basis points, 10000 = 100%)
Response Fields
Encoded function call data for the transaction
Address of the vault contract
Required gas fee for the transaction
Example Usage
Full Position Close
Partial Position Close
Modify Take Profit/Stop Loss
Example Response
Common Use Cases
-
Full Position Close
- Only specify
positionId
and optionallyallowedPrice
- Closes entire position
- Only specify
-
Partial Position Close
- Specify
positionId
,sizeDelta
, and optionallyallowedPrice
- Closes specified amount of position
- Specify
-
Modify Take Profit/Stop Loss
- Specify
positionId
,takeProfit
/stopLoss
, and corresponding close percentages - Updates or adds take profit/stop loss orders without closing position
- Specify
Notes
allowedPrice
helps prevent slippage - transaction will fail if price moves beyond this limit- Close percentages are in basis points (10000 = 100%)
- Take profit and stop loss can be modified without closing the position
sizeDelta
must be less than or equal to current position size
Body
ID of the position to close
Maximum/minimum allowed price for closing
Amount to decrease the position by
New stop loss price
Percentage to close at stop loss
New take profit price
Percentage to close at take profit