Take Profit

Sometimes you want to set a specific percentage of profit for an order. This is what TakeProfit will allow you to do. It establishes a point at which an order converts to a market order and exits your position with profit. Here is an example:

const tp = new TakeProfitSwap({
    amountIn:  units.inBNETH("18000"),
    tokenIn: matic,
    tokenOut: usdc,
    slippage: new Slippage(.5, false),
    profitPercentage: 10,
    startingPrice: new Price({
        inAmount: units.inBNETH("1000"),
        inToken: matic,
        outAmount: units.inBNETH("950"),
        outToken: usdc
    })
});

Here you are telling Dexible to execute when the market price reaches 10% above the starting price of .95 USDC per MATIC, which is 1.045 USDC. At that point, Dexible will swap 18k MATIC tokens at market rate.

Last updated