Skip to main content

What You’ll Build

An auto-rebalancing bot that runs on a loop and:
  1. Monitors your open LP positions every 60 seconds
  2. Detects when a position goes out of range (stops earning fees)
  3. Zap-Out — withdraws liquidity back to SOL
  4. Zap-In — re-enters with a new position centered around the current price
No smart contract knowledge needed — the bot uses LP Agent’s Open API for everything.
All transactions are landed via LP Agent’s built-in Jito integration, which provides a significantly better landing rate than submitting directly via RPC — and it’s completely free.

How Rebalancing Works

When the price moves outside your position’s bin range, the position stops earning fees. A rebalance fixes this by closing the old position and opening a new one centered around the current price.

The Bot’s Decision Loop

Every check interval, the bot follows this flow:

Key Decisions the Bot Makes


Prerequisites

  • An LP Agent API key
  • A Solana wallet with SOL for transaction fees
  • Node.js >= 18

Configuration

Before looking at the code, here are the settings you’ll want to tune:

Customization Ideas

These snippets show how to extend the bot. Each one plugs into the rebalance loop.

Add a Stop-Loss

Exit positions that have lost too much value — don’t throw good money after bad:

Add Discord Notifications

Get alerted when a rebalance happens:

Dynamic Bin Range

Use wider ranges for volatile pools, tighter for stable ones:

Filter by Pool Type

Only rebalance DLMM positions (skip DAMM V2):

Running in Production

With PM2

With Docker

Environment Variables

For production, never hardcode secrets:

API Endpoints Used

Tips

  • Check interval: 60s is a good default. Too fast = unnecessary API calls. Too slow = missed fees while out of range.
  • Gas costs: Each rebalance costs ~0.01-0.03 SOL. Factor this into profitability.
  • Bin range: Wider range = fewer rebalances but lower fee APR. Find the sweet spot for your pair.
  • Transaction landing: LP Agent’s landing endpoints use Jito bundles — no need to set up your own Jito integration.

Complete Bot Script

Here’s the full bot ready to copy-paste and run:

Next Steps