POST
/
api
/
closeposition

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

positionId
string
required

ID of the position to close or modify

sizeDelta
number

Optional. Amount to decrease the position by. If not provided, closes entire position

allowedPrice
number

Optional. Maximum (for longs) or minimum (for shorts) allowed price for closing

takeProfit
number

Optional. New take profit price. Set to modify existing take profit order

stopLoss
number

Optional. New stop loss price. Set to modify existing stop loss order

takeProfitClosePercent
number

Required if takeProfit is set. Percentage to close at take profit (in basis points, 10000 = 100%)

stopLossClosePercent
number

Required if stopLoss is set. Percentage to close at stop loss (in basis points, 10000 = 100%)

Response Fields

calldata
string

Encoded function call data for the transaction

vaultAddress
string

Address of the vault contract

requiredGasFee
string

Required gas fee for the transaction

Example Usage

Full Position Close

Partial Position Close

Modify Take Profit/Stop Loss

Example Response

{
  "calldata": "0x4d59524546455252414c434f4445000000000000000000000000000000000000",
  "vaultAddress": "0xe3ca135782e4a17aFb31a63ee3b15351C891A1A2",
  "requiredGasFee": "0.0012"
}

Common Use Cases

  1. Full Position Close

    • Only specify positionId and optionally allowedPrice
    • Closes entire position
  2. Partial Position Close

    • Specify positionId, sizeDelta, and optionally allowedPrice
    • Closes specified amount of position
  3. Modify Take Profit/Stop Loss

    • Specify positionId, takeProfit/stopLoss, and corresponding close percentages
    • Updates or adds take profit/stop loss orders without closing position

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

application/json
positionId
string
required

ID of the position to close

allowedPrice
number

Maximum/minimum allowed price for closing

sizeDelta
number

Amount to decrease the position by

stopLoss
number

New stop loss price

stopLossClosePercent
number

Percentage to close at stop loss

takeProfit
number

New take profit price

takeProfitClosePercent
number

Percentage to close at take profit

Response

200 - application/json
calldata
string
required

Encoded function call data

vaultAddress
string
required

Address of the vault contract

requiredGasFee
string

Required gas fee for the transaction