Close/Decrease a Market position

In order to close an existing position:

  1. Call OrderManager.createDecreasePosition with

  • _collateralToken: address of the collateral token for the position.

  • _indexToken: address of the index token of the position.

  • _collateralDelta: keep this as 0 if you do not want to adjust the leverage for the position.

  • _sizeDelta: the USD value of the change in position size.

  • _isLong: whether the position is long or short

  • _receiver: the address to receive the withdrawn tokens

  • _acceptablePrice: price at which you want your position request to be executed

  • _executionFee: can be set to OrderManager.minExecutionFeeMarketOrder

  1. After this transaction, a request to close your position will be created, and a keeper will execute your request.

  2. Once the request is executed, the funds are transferred to _receiver of the position request.

Note that for both createIncreasePosition and createDecreasePosition, send the equivalent amount of native token in msg.value as specified in _executionFee, or else your request won’t be entertained.

Last updated