Before you begin
- Get an API key with options taker access. Contact Us.
- Use a wallet that holds the WETH collateral and ETH for gas. The wallet must hold no option tokens of the instrument that you sell.
- Have the URL of an Ethereum RPC node.
- Install the Python packages:
pip install httpx web3. - Set the environment variables
BEBOP_API_KEY,ETH_RPC_URL, andPRIVATE_KEY. Do not put the private key in the source code.
1
Find an instrument
List the active WETH calls and choose one where The output is similar to:If
canSell is true. The instrument field is the option token address.The Python example chooses the nearest expiry and its highest strike. Change the selection to the strike and the expiry that you want to sell.nextCursor is not null, more instruments are on the next page. See List instruments.2
Set the amount
The amount is in raw collateral units. A WETH call uses 18 decimals, so 0.01 WETH is For a put, the amount is in USDC (6 decimals): the strike times the underlying amount. See Amounts.
10000000000000000.3
Approve the collateral to the Greek Factory
The Greek Factory pulls the collateral when the trade settles. Read its address from the
factory field of the instrument.4
Grant the settlement contract the open permission
Add mask
3 (TRANSFER | MINT) for the settlement contract. Use addPermissions. setPermissions replaces the complete mask.5
Request a quote
Request a sell-to-open quote with The output is similar to:
validate=true. Bebop then also checks the wallet balance, allowance, and permission, and lists any problem in issues.premium is the USDC that the wallet receives, after the Bebop fee, in raw units (6 decimals). In this example, the wallet receives 0.643 USDC. fee is already deducted from premium.6
Send the transaction
Send If
tx from the wallet in taker_address. The quote is firm until expiry, a Unix timestamp in seconds. Do not change tx.data.expiry passes before you send, request a new quote.7
Verify the position
Read the position with the The output is similar to:The wallet now holds 0.01 RT of the instrument, and its WETH balance is 0.01 lower.
positionId from the quote. Bebop returns 404 until it indexes the transaction, so try again while the response is 404.