Skip to main content
This walkthrough reads a market on Solana mainnet-beta, quotes it, then trades from a local keypair. Steps 1 and 2 need no wallet or funds.

Prerequisites

  • Python 3.10 or later.
  • A Solana mainnet-beta RPC endpoint. The public endpoint works for reads; use a dedicated provider for trading.
  • For steps 3 to 5: a keypair holding USDC (in its associated token account) and a little SOL for transaction fees and, on a first buy, the position account’s rent.

1. Read a market

2. Quote

3. Buy and sell

4. Build, simulate, then send

5. Redeem and close

The rent goes back to whoever funded the position account, which can differ from the owner who signs.

Handling errors

See Error handling for the full table; the Python classes and codes are the same.

Next

Runnable examples

Read-and-quote, buy-and-sell, and redeem-and-close scripts.