Dexible SDK v1.0
  • Dexible API & SDK
  • Overview
    • How Dexible Works
      • Costs
      • Verification and Validation
  • Modules
  • Major SDK Components
    • Token
    • Quotes
    • Algos
      • Limit
      • Stop Price Algos
      • TWAP
      • StopLimit Algo
    • Order
    • Contact
  • Policies
  • Policy Overview
    • Custom Algos
  • Reporting
    • Summary Reports
    • Auditable Records
Powered by GitBook
On this page
  1. Major SDK Components
  2. Algos

Limit

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.

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 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
                }),
   }
}); 
import dexible
from asyncio import run 
WETH_MAINNET = "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2"
MATIC_MAINNET = "0x7d1afa7b718fb893db30a3abc0cfc608aacfebb0"

## ...create DexibleSDK called sdk...

## Use await instead if called within an async context:
# token_in = await sdk.token.lookup(WETH_MAINNET)
# token_out = await sdk.token.lookup(MATIC_MAINNET)
token_in = run(sdk.token.lookup(WETH_MAINNET))
token_out = run(sdk.token.lookup(MATIC_MAINNET))

limit = sdk.algo.create(
    type=sdk.algo.types.Limit,
    ## or just:
    # type="Limit",
    gas_policy=dexible.policy.GasCost(
        gas_type=sdk.GasPolicyTypes.FIXED,
        amount=dexible.common.as_units(25, 9)),
    slippage_percent=.5,
    price=dexible.Price.units_to_price(
        in_token=token_in,  # WETH
        out_token=token_out,  # MATIC
        in_units=1,  # WETH in
        out_units=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).

PreviousAlgosNextStop Price Algos

Last updated 2 years ago