TP/SL Orders

Automate exits with take-profit and stop-loss orders.

Take-Profit & Stop-Loss Orders

Lavarage supports server-side TP/SL orders that automatically close your position when a price target is hit.

How It Works

  1. You create an order specifying a trigger price
  2. The server monitors the asset price continuously
  3. When the trigger is hit, the server signs and submits a close transaction using your Privy wallet
  4. The position is closed at the best available market price

Creating a Take-Profit Order

curl -X POST https://api.lavarage.xyz/api/v1/orders \
  -H "x-api-key: YOUR_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "positionAddress": "YOUR_POSITION_ADDRESS",
    "walletId": "privy-wallet-id",
    "orderType": "TAKE_PROFIT",
    "triggerPrice": "160.00",
    "side": "LONG"
  }'

Creating a Stop-Loss Order

curl -X POST https://api.lavarage.xyz/api/v1/orders \
  -H "x-api-key: YOUR_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "positionAddress": "YOUR_POSITION_ADDRESS",
    "walletId": "privy-wallet-id",
    "orderType": "STOP_LOSS",
    "triggerPrice": "130.00",
    "side": "LONG"
  }'

Order Behavior by Side

SideTake ProfitStop Loss
LONGTriggers when price >= targetTriggers when price <= target
SHORTTriggers when price <= targetTriggers when price >= target

Managing Orders

List orders for a position:

curl "https://api.lavarage.xyz/api/v1/orders?positionAddress=YOUR_POSITION" \
  -H "x-api-key: YOUR_KEY"

Cancel an order:

curl -X DELETE https://api.lavarage.xyz/api/v1/orders/ORDER_ID \
  -H "x-api-key: YOUR_KEY"

Order Statuses

StatusMeaning
ACTIVEMonitoring price, not yet triggered
EXECUTEDPrice target hit, position closed
CANCELLEDCancelled by user
FAILEDExecution attempted but failed (e.g. insufficient liquidity)

Important Notes

  • You can have one TP and one SL per position simultaneously
  • Orders require a Privy wallet ID for server-side transaction signing
  • Execution is best-effort — in extreme volatility, the executed price may differ from the trigger
  • Orders are automatically cancelled when a position is manually closed