Quick Start

Open your first leveraged position in 5 minutes.

Open your first leveraged position in 5 minutes.

Prerequisites

  • A Lavarage API key (visit https://lavarage.xyz/partners to apply for API access)
  • A Solana wallet with SOL for collateral and transaction fees
  • Node.js 18+ or any HTTP client

Step 1: Find a Pool

Browse available offers to find a market you want to trade:

curl https://api.lavarage.xyz/api/v1/offers?includeTokens=true&search=SOL&limit=5

Pick an offer and note the publicKey, maxLeverage, and availableForOpen.

Step 2: Get a Quote

Preview the expected entry price:

curl -X POST https://api.lavarage.xyz/api/v1/positions/quote \
  -H "x-api-key: YOUR_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "offerPublicKey": "POOL_ADDRESS",
    "userPublicKey": "YOUR_WALLET",
    "collateralAmount": "1000000000",
    "leverage": 3,
    "side": "LONG",
    "slippageBps": 50
  }'

1000000000 lamports = 1 SOL. Adjust collateral based on the token's decimals.

Step 3: Open the Position

For SOL LONG, pass quoteTokenMint: USDC explicitly — there is no SOL/SOL offer. The example below uses cbBTC as the base token and USDC as the quote so you can copy/paste and get a real response.

curl -X POST https://api.lavarage.xyz/api/v1/positions/open-by-token \
  -H "x-api-key: YOUR_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "baseTokenMint": "cbbtcf3aa214zXHbiAZQwf4122FBYbraNdFqgw4iMij",
    "quoteTokenMint": "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
    "userPublicKey": "YOUR_WALLET",
    "collateralAmount": "10000000",
    "leverage": 3,
    "side": "LONG",
    "slippageBps": 50
  }'

baseTokenMint is cbBTC (the token you want exposure to); quoteTokenMint is USDC (the collateral). collateralAmount is in quote-token smallest units — 10,000,000 = 10 USDC.

For advanced use, you can also use POST /api/v1/positions/open with a specific offerPublicKey instead of baseTokenMint.

This returns a transaction field — a bs58-encoded VersionedTransaction. Sign and submit it:

import { Connection, VersionedTransaction } from '@solana/web3.js';
import bs58 from 'bs58';

const tx = VersionedTransaction.deserialize(bs58.decode(response.transaction));
tx.sign([yourKeypair]);

const connection = new Connection('https://api.mainnet-beta.solana.com');
const sig = await connection.sendTransaction(tx);
console.log('Position opened:', sig);

Step 4: Monitor Your Position

curl https://api.lavarage.xyz/api/v1/positions?status=OPEN&owner=YOUR_WALLET \
  -H "x-api-key: YOUR_KEY"

Step 5: Close the Position

curl -X POST https://api.lavarage.xyz/api/v1/positions/close \
  -H "x-api-key: YOUR_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "positionAddress": "POSITION_ADDRESS",
    "userPublicKey": "YOUR_WALLET",
    "slippageBps": 50
  }'

Sign and submit the returned transaction the same way.

What's Next?