getTradeData

This function uses the SDK's matching algorithm to find a trade route given a set of trading parameters.

public async getTradeData(
    sourceToken: string,
    targetToken: string,
    amount: string,
    tradeByTargetAmount: boolean,
    filter?: (rate: Rate) => boolean
  )
NameTypeDescription

sourceToken

token address

The address of the token being swapped in.

targetToken

token address

The address of the token received.

amount

string (number)

The number of tokens being traded in, if using tradeBySourceAmount, or the number of tokens to receive.

tradeByTargetAmount

boolean

True: Generates the trade using tradeByTargetAmount False: Generates the trade using tradeBySourceAmount

filter

list (optional)

This optional parameter forces the route to only include strategies that allow trading at the specified rate. Rate is calculated as input/output. type Rate = { input: BigNumber; output: BigNumber; };

Returns

This function returns the trade route, including the following parameters:

NameTypeDescription

tradeActions

list

A list of trade actions that can be passed into composeTradeTransaction, a function that returns an unsigned transaction.

actionsTokenRes

list

A list of trade actions in human-readable format.

totalSourceAmount

string (number)

The total amount of source tokens going into the trade.

totalTargetAmount

string (number)

The total number of target tokens received by the trade.

effectiveRate

string (number)

The effective rate of exchange, calculated from the total input vs total output.

Last updated