This guide walks through opening a 2× long on SOL-PERP from a clean wallet
state, using the Codama-generated TS client.
Prerequisites
- Wallet funded on devnet (
solana airdrop 2)
- USDC (devnet) in the wallet, mint is on the program constants page
- Perp market initialized (it is, on devnet, at
market_index = 0)
1. Create a user account
2. Deposit USDC collateral
3. Post the oracle update
4. Place a market long
5. Close the position
A closing order is a market order in the opposite direction:
Realized PnL flows into user_account.collateral automatically. Withdraw with
getWithdrawCollateralInstruction (authority only, delegates cannot withdraw).
Things to watch
If the oracle post instruction is not prepended, place_order will revert with
InvalidOraclePrice or StaleOracle. The price must land on-chain in the
same transaction as the trade.
The matching loop processes up to 4 fills per tx. For larger fills, issue
multiple place_order transactions, the remaining size will walk the book on
each call.