Skip to main content
Each recipe below is one task, written as a short async snippet. They focus on the order of calls and the fields that matter. For every parameter and return type, see the Reference.

Setup

Every recipe assumes this setup. vault is the address of a vault your key manages. Where a recipe uses lbPair (a DLMM pool) or position (a DLMM position), it is an address you already read with searchPools or getStrategies.
These recipes run against Solana mainnet by default. Each execute call signs and sends real transactions.

Check a vault’s state

Read what the vault holds and which strategies are open. A token without a price makes holdings.partial true. A missing value is not zero.

Quote and swap with Jupiter

Before a vault can hold a token, it needs a Jupiter strategy for that token. Open it once, quote, then swap.
  1. Look up the token and warn if Jupiter has not verified it.
  2. Open the token’s Jupiter strategy with jupiter/initialize. Skip this when it already exists.
  3. Quote the swap with getQuote.
  4. Run jupiter/swap with the same amount and slippage.
To sell a token back to the deposit mint and close its strategy in one transaction, sweep it:
The API refuses jupiter/sweep with HTTP 409 while an open DLMM position or limit order still uses the token. Close those first.

Open a DLMM position by price

Find a pool, turn a price range into bins with binRangeForPrices, and open the position. Prices are token Y per token X.
range.sides tells you which token the range can take. A range entirely below the active bin takes only token Y, and a range entirely above it takes only token X. A range wider than 70 bins becomes several transactions, which execute follows on its own. To create an empty position first and fill it later, use dlmm/initialize and read the new address from the outcome:

Add and remove liquidity

Add to every bin of a position, or to an inclusive sub-range of it. Remove a share of liquidity in basis points.

Claim fees, zap out, and close

Flip one side of a position

dlmm/flip removes the liquidity from a bin range and re-adds that token there as Bid-Ask, in one transaction. The range must hold only one token, so use flipSide and flipRange to compute it from the position and the active bin.

Place a DLMM limit order

An ask rests token X in bins above the active bin and sells it for token Y. A bid rests token Y in bins below the active bin and buys token X. List 1 to 50 bins in strictly increasing order.
Fills and fees stay in the order until you cancel it. Read the order from getStrategies, then cancel some bins or all of them. Once the order is empty, its strategy closes in the same transaction.

Trade Phoenix perpetuals

Phoenix needs a USDC vault. Set it up once, fund collateral, then trade.
  1. Record the Phoenix strategy with phoenix/initialize.
  2. Register the trader with onboardPhoenix. Phoenix co-signs this transaction, so it has its own method.
  3. Move USDC into collateral with phoenix/deposit.
Place a market order with a take-profit and stop-loss, or a post-only limit order. size and prices are decimals, not base units.
Move or remove the take-profit and stop-loss later with phoenix/tpsl. A null price removes that leg.
Cancel resting orders, close out, and withdraw collateral:
openOrders is null when Phoenix’s API is down. Handle null before you read it.

Create and update a vault

vault/initialize needs a key that is not limited to specific vaults. Fees are basis points. Caps and minimums are base units.
vault/update changes only the fields you pass:

Handle every outcome

A bot should treat each Outcome differently. Never resend after unresolved, and read state before you retry after failed.

Use a custom signer

A TransactionSigner is any object with a publicKey and a signTransaction method. A hardware wallet or a KMS can sign instead of a local keypair. The signer must add its signature and keep the signatures already on the transaction.