Before you begin
- Complete the Quickstart. The examples use its settings,
send()helper,ERC20_ABI, andFACTORY_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
409PositionConfirming. - 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 For a close,
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.premium is the total USDC that the wallet pays, including the Bebop fee.5
Send the transaction
Send
tx from the wallet before expiry.6
Verify the result
Read the position again until After a full close,
closedAmount shows the close. Bebop indexes the transaction some seconds after it is mined.status is closed, remainingAmount is "0", and rtBalance is "0". After a partial close, status stays open. The collateral is back in the wallet.