TrailingStop

To protect your profits, you may want to have Dexible watch the market price of an asset and as long as it keeps going up in price, keep track of its peak price. No matter what, if it falls below a certain percentage of that peak price, you want to get out of the market as quickly as possible. This is what a trailing stop order will do. Dexible will keep a running record of the peak price and if it suddenly falls below your threshold, it will convert to a market order. Here is an example:

const ts = new TrailingStopSwap({
    amountIn:  units.inBNUnits("18000"),
    tokenIn: matic,
    tokenOut: usdc,
    slippage: new Slippage(.5, false),
    spotPercentage: 10,
});

In this example, it tells Dexible to keep watching the price of the MATIC-USDC market and if the price drops 10% off its peak at any time, exit the 18k MATIC position to USDC via a market order.

Last updated