The Limit algo requires a price policy that tells Dexible what price you want the system to look for when trading. Let's cover what "price" means so that it's clear how Dexible expects prices to be presented.


In practical terms, a price is how much of one thing translates into an amount of another thing. You might say the price of 1 banana is 2 oranges. This is expressing the price in orange terms-- meaning there are 2 oranges for every 1 banana. If we want to express the price by what we are receiving (bananas), we simply flip the values mathematically--meaning 1 orange is worth 1/2 of a banana. This is critical to understand how token prices work in Dexible, and really most DEX's in general. You must specify the input and output tokens and amounts so that Dexible knows clearly what price you are looking for. What complicates things a little more, is that not all tokens have the same number of decimals. This is why all token prices must use Token references that we looked up earlier--because those references include decimals for the tokens. Orders that submit prices that use decimal places mismatching on-chain decimals will likely result in unexpected outcomes. Here is an example Limit order using this price mechanism:

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

let limit = sdk.algo.create({
   type: sdk.algo.types.Limit,
   gasPolicy: {
      type: sdk.gasPolicyTypes.RELATIVE,
      deviation: 0
   slippagePercent: .5,
   price: Price.unitsToPrice({
                    inToken: tokenIn, //WETH
                    outToken: tokenOut, //MATIC
                    inUnits: 1, //WETH in
                    outUnits: 2056.7668 //MATIC out

This example tells Dexible to only execute a round if the price is at least .0004862 ETH for a single MATIC token (1/2056.7668). Dexible will compute the expected output given your price and if the market is at least as good as what you expect, it will execute the round (i.e. the price may be better than your expectation).

Last updated