Order ERC20

Demo for making an immediate swap

Mini-order

To support small quantity trading, we introduce an additional concept tradeCost, which is the minimum gas fee when a trade transaction is uplink to Ethereum.

Let's take LRC-ETH trading as an example.

Below are the steps:

Query api/v3/exchange/tokens to get the dust value of orderAmounts for both LRC and ETH

The dust value is the minimum value to pass Relayer check. Any amount less than "dust" can't be traded.

In this case, we will get both minTokenLRC and minTokenETH after getting dust value.

If a user wants to convert LRC to ETH, the set LRC amount can't be less than minTokenLRC and the converted ETH amount can't be less than minTokenETH.

Caculate the cost by considering slippage

minCostLRCSlip = minCostLRC/(1-slippage)
minCostETHSlip = minCostETH/(1-slippage)

Price impact update

  1. sellTokenMinAmount = baseOrderInfo.minAmount from LoopringAPI.userAPI.getMinimumTokenAmt({accountId,marke}, apiKey)

  2. {output} from sdk.getOutputAmount(input: sellTokenMinAmount, isAtoB: isAtoB,…}).output

  3. PriceBase = output / sellTokenMinAmount

  4. tradePrice = calcTradeParams.minReceive / userInputSell

  5. priceImpact = 1 - tradePrice/PriceBase - 0.005

  6. If priceImpact < 0 priceImpact = 0 Else priceImpact

LRC-ETH : for Base to Quote

An example swap of ETH into LRC.

Calculate swap function

Get apikey & eddsaKey

Mock Swap Data

Last updated

Was this helpful?