Custom Algos

Since Dexible views algos as a name plus a collection of policies, you have tremendous flexibility over order execution. Every algo requires the gasPolicy and slippage policies. Beyond that, the Limit, StopLimit, and TWAP algos have specific policy requirements as well (namely, LimitPrice, StopPrice, and BoundedDelay). If you truly want to start from scratch, you can apply policies to a Market algo to express to Dexible how you want the order to execute.

PriceRange Market Order

Suppose you want to simply specify a price range for an order. Unlike limit, you want to execute if the price is above or below a certain price point (often called price 'bands'). Here is what you can do:

import {Algos, Price, Policies, SDK} from 'dexible-sdk';

const {GasCost, Slippage, PriceBounds} = Policies;

const main = async () => {
   //create SDK instance since we'll need it later
   let sdk = new SDK(...);
   
   let tokenIn = await sdk.token.lookup(...);
   let tokenOut = await sdk.token.lookup(...);
   
   let policies = [
      new GasCost({
         gasType: sdk.gasPolicyTypes.RELATIVE,
         deviation: 0
      }),
      new Slippage({
         amount: .5
      }),
      new PriceBounds({
         basePrice: new Price({
            inToken: tokenIn,
            outToken: tokenOut,
            inUnits: 1,
            outUnits: 2500
         }),
         lowerBoundPercent: 2,
         upperBoundPercent: 2 
      })
   ];
   
   let algo = new Algos.Market({
      //maxRounds: 10,
      policies
   });
}

main();

Even though this is labeled as a "market" order, it will not behave like a market order because we've added specific policies that tell Dexible how to execute. It will restrict the execution to a specific price band.

Order Matters

The order of the policies array is the exact order of evaluation within Dexible's infrastructure. The first non-passing policy will stop evaluation for the order. In certain cases, the policy will force a cancel. We recommend putting those policies ahead of others to short circuit evaluation.

Extending Policies

We will add more policy types as we expand Dexible. If you find that you need a policy that is missing, please contact us and we will evaluate your use case and add policies accordingly.

Last updated