# 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
  )
```

<table><thead><tr><th width="221">Name</th><th width="152.33333333333331">Type</th><th>Description</th></tr></thead><tbody><tr><td>sourceToken</td><td>token address</td><td>The address of the token being swapped in. </td></tr><tr><td>targetToken</td><td>token address</td><td>The address of the token received.</td></tr><tr><td>amount</td><td>string (number)</td><td>The number of tokens being traded in, if using tradeBySourceAmount, or the number of tokens to receive.</td></tr><tr><td>tradeByTargetAmount</td><td>boolean</td><td>True: Generates the trade using tradeByTargetAmount<br>False: Generates the trade using tradeBySourceAmount</td></tr><tr><td>filter</td><td>list (optional)</td><td>This optional parameter forces the route to only include strategies that allow trading at the specified rate. Rate is calculated as input/output. <br><code>type Rate = { input: BigNumber; output: BigNumber; };</code></td></tr></tbody></table>

### Returns

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

<table><thead><tr><th width="221">Name</th><th width="152.33333333333331">Type</th><th>Description</th></tr></thead><tbody><tr><td>tradeActions</td><td>list</td><td>A list of trade actions that can be passed into composeTradeTransaction, a function that returns an unsigned transaction.</td></tr><tr><td>actionsTokenRes</td><td>list</td><td>A list of trade actions in human-readable format.</td></tr><tr><td>totalSourceAmount</td><td>string (number)</td><td>The total amount of source tokens going into the trade.</td></tr><tr><td>totalTargetAmount</td><td>string (number)</td><td>The total number of target tokens received by the trade.</td></tr><tr><td>effectiveRate</td><td>string (number)</td><td>The effective rate of exchange, calculated from the total input vs total output. </td></tr></tbody></table>

###


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.carbondefi.xyz/developer-guides/carbon-defi-sdk/sdk-functions/gettradedata.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
