Skip to main content

Automated Strategies

Getting Started

In this guide, we will write a nodejs script that calls the defiedge strategy smart contract for atomizing the rebalance functionality. This is an example of a rebalance bot which checks the current price of token1 per token0 . If the current price of token1 per token0 is less than to the lower price or token1 per token0 price is greater than to the upper price then it should rebalance the strategy by calling DeFiedge strategy contract rebalance function

For Creating Rebalance bot Manager needs to integrate following APIs

Step 1: Swap Amount API.

Step 2: Precision calculation API.

Step 3: 1Inch Router API.

Step 4: You can integrate your own Back Tested API for ranges.

DeFiegde API Documentation :-

  • Swap Amount API :-

You can find DefiEdge API endpoint below :


Methods For Calling the API

  1. This method is used for getting the liquidity data from strategy

       Request :

       GET: matic/{{Input_Strategy_Address}}/liquidity

       Response :

  1. This method is used for calculating the liquidity amount ratio with respect to ranges for swap

        Request :

       POST: /calculations/swap_amounts

       POST data:

Nodejs Example for above APIs

 //API used for calculating liquidity data of strategy by providing strategy address
let liquidity = await axios.get(`${CONFIG.STRATEGY_ADDRESS}/liquidity`);
console.log("liquidity: ",

//API used for calculating swap amount via providing Post data

let swapAmounts = await"", {
price: priceToken1PerToken0,
ranges: [[Number(newlowerPrice.toSignificant(6)),Number(newupperPrice.toSignificant(6)),1]],
f: fee
console.log("swapAmounts: ",
var swapData;
if( == 0 && == 0){
swapData = "0x"
console.log("-no need for swap")
} else {
console.log("swap data")