Carbon DeFi Dev
  • Carbon DeFi
    • Introducing Carbon DeFi
      • What Makes Carbon DeFi Unique?
      • Fees & Payments
      • Resources
    • Security & Audits
  • Contracts & Functions
    • Contracts
      • CarbonController
      • CarbonVortex
      • CarbonVortexBridge
      • Deployments
        • Mainnet Contracts
        • Testnet Contracts
    • CarbonController Functions
      • Write Functions
        • Transaction Prerequisites
          • approve() / allowance()
        • Trade
          • tradeBySourceAmount()
          • tradeByTargetAmount()
        • Strategy Management
          • createStrategy()
          • updateStrategy
          • deleteStrategy()
      • Read Functions
        • controllerType()
        • tradingFeePPM()
        • pairTradingFeePPM()
        • pair()
        • pairs()
        • strategy()
        • strategiesByPair()
        • strategiesByPairCount()
        • calculateTradeSourceAmount()
        • calculateTradeTargetAmount()
      • Data & Events
        • TradingFeePPMUpdated()
        • PairCreated()
        • StrategyCreated()
        • StrategyDeleted()
        • StrategyUpdated()
        • TokensTraded()
        • FeesWithdrawn()
    • CarbonVortex Functions
      • Write Functions
        • trade()
        • execute()
      • Read Functions
        • amountAvailableForTrading()
        • availableTokens()
        • expectedTradeInput()
        • expectedTradeReturn()
        • finalTargetToken()
        • minTargetTokenSaleAmount()
        • minTokenSaleAmount()
        • pairDisabled()
        • priceDecayHalfLife()
        • rewardsPPM()
        • targetToken()
        • targetTokenPriceDecayHalfLife()
        • targetTokenSaleAmount()
        • tokenPrice()
        • totalCollected()
        • tradingEnabled()
    • CarbonVortexBridge Functions
      • Write Functions
        • Bridge()
  • Rest API
    • Carbon DeFi Public REST API
  • Developer Guides
    • Carbon DeFi SDK
      • Getting started
      • Interacting with the SDK
        • Managing Strategies
        • Performing Trades
        • Getting User and Pair Data
        • Collecting Liquidity Data
      • SDK Functions
        • constructor
        • startDataSync
        • getCachedPairs
        • hasLiquidityByPair
        • getLiquidityByPair
        • getUserStrategies
        • getTradeData
        • composeTradeByTargetTransaction
        • composeTradeBySourceTransaction
        • createBuySellStrategy
        • updateStrategy
        • deleteStrategy
        • getMinRateByPair
        • getMaxRateByPair
        • getRateLiquidityDepthByPair
    • The Carbon DeFi versus Uniswap V3 Invariant Functions
    • Carbon DeFi Subgraph
      • Accessing the Subgraph
      • Creating Subgraph Queries
      • Subgraph Query in Python
      • Sample Subgraph Queries
    • Using CarbonVortex
      • CarbonVortex Dynamics
Powered by GitBook
On this page
  • Returns
  1. Developer Guides
  2. Carbon DeFi SDK
  3. SDK Functions

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
  )
Name
Type
Description

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:

Name
Type
Description

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.

PreviousgetUserStrategiesNextcomposeTradeByTargetTransaction

Last updated 5 months ago