Limit

The LimitSwap requires a price 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.

Prices

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 used 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 {Price, LimitSwap} from 'dexible-sdk';
...

let limit = new LimitSwap({
    amountIn:  units.inBNETH("1"),
    tokenIn: weth,
    tokenOut: matic,
    slippage: new Slippage(.5, false),
    price: new Price({
        inAmount: units.inBNETH(".0004862"),
        inToken: weth,
        outAmount: units.inBNETH("1"),
        outToken: matic
    }),
    customizations: {
        ...
    }
});

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