Stop Price Algos

A very useful trading tool is the ability to set a stop price on the value of a token. A "stop" is really just a trigger price that results in some action being taken once the trigger price is tripped. From Dexible's perspective, StopLoss, and what might be called a StopLimit, just uses a StopPrice policy. That policy specifies a trigger price and whether the market price needs to be above or below that trigger before Dexible will execute the round.


When you want to protect an asset position from a dramatically moving downside, you would tell Dexible to watch for a trigger price and execute the order when the market price is below (or not above) the given price. When using the algo factory, it looks like this:

let algo = sdk.algo.create({
    type: sdk.algo.types.StopLoss,
    triggerPrice: Price.unitsToPrice({
        inToken: tokenIn, //WETH
        outToken: tokenOut, //MATIC
        inUnits: 1, //weth in
        outUnits: 1800 //MATIC out
    isAbove: false,
    maxRounds: 1,
    gasPolicy: {
        type: sdk.gasPolicyTypes.RELATIVE
        deviation: 0
    slippagePercent: .5

This example has a few new items. The triggerPrice should be self-explanatory; but the isAbove flag tells Dexible that the market price does NOT have to be above the trigger before the stop trigger is tripped. Once the trigger activates, it's like a circuit breaker and any subsequent rounds for the order will be executed as a Market order.

The maxRounds tells Dexible that when executing this order, only a single round must be used and you don't care what the resulting price impact will be. In this case, a stop loss is attempting to bail out as quickly as possible so a single round is the quickest way to get out.

Later we will show you how could also inject a price range policy in the order to execute the trigger order as a kind of limit order to keep losses within a specific range.


Another way to use this StopPrice policy is in a stop limit order. This allows you to specify an upside trigger to trip when a token price breakout happens. If you want to use the factory to create this order, simply set the isAbove parameter to true. This will turn into a market buy order when the price hits at or above the specified price. And just like the StopLoss order, later we'll discuss adding price range policies to an algo so that the post-trigger execution is not merely a Market algo.

Last updated