Skip to main content
This guide shows how to close all or part of an open position before expiry. At the end, the wallet has paid the close premium in USDC and has the collateral back.

Before you begin

  • Complete the Quickstart. The examples use its settings, send() helper, ERC20_ABI, and FACTORY_ABI.
  • The position must be open, and the wallet must hold at least as many receipt tokens (RT) as you close.
  • Wait until the open is confirmed, about 30 seconds after it is mined. Before that, a full close quote returns 409 PositionConfirming.
  • Request the close quote more than 30 seconds before expiration. After that, Bebop does not quote the instrument.
  • The wallet needs USDC for the premium and ETH for gas.
1

Find the position

List the positions of the API key and choose the open position of the wallet. If you have more than 200 positions, read the next pages with nextCursor.
2

Grant the settlement contract the burn permission

Add mask 4 (BURN) for the settlement contract on the Greek Factory of the instrument. With this permission, the trade burns the returned option tokens together with the wallet’s RT and releases the collateral.
3

Approve USDC to the settlement contract

The settlement contract takes the close premium from the wallet. Approve the largest premium that you accept, in raw USDC units (6 decimals).
4

Request a close quote

To close the full position, omit amount. To close part of it, set amount in raw option-token units. The amount must be at or above the minimum amount. The remainder must also be at or above the minimum, unless amount is the full RT balance of the wallet.
For a close, premium is the total USDC that the wallet pays, including the Bebop fee.
5

Send the transaction

Do not move RT out of the wallet between the quote and the transaction. The transaction can then succeed with less RT burned and less collateral returned.
Send tx from the wallet before expiry.
6

Verify the result

Read the position again until closedAmount shows the close. Bebop indexes the transaction some seconds after it is mined.
After a full close, status is closed, remainingAmount is "0", and rtBalance is "0". After a partial close, status stays open. The collateral is back in the wallet.

If it does not work