# Basket Trade (m:n swap)

Basket trades or m:n swaps allow you to rebalance a portfolio of assets in one go. This means you can specify a base allocation (m) consisting of one or many assets and a target allocation (n) with one or many assets. M and n can be the same assets in a different percentual allocation but also completely different assets.

For specific use-case specific descriptions see:

* [Wallet](/31third-api/basket-trade-m-n-swap/wallet.md)
* [Enzyme](/31third-api/basket-trade-m-n-swap/enzyme.md)
* [SetProtocol](/31third-api/basket-trade-m-n-swap/setprotocol.md)

### Usage example with ethers.js

The API returns a DTO containing the following properties:

```typescript
export interface RebalancingResponseDto extends BaseEntityModel {
  ...
  txHandler: Address;    // address of deployed BatchTrade
  txData: string;        // calldata containing encoded Trades and BatchTradeConfig
  txValue: BigNumberDto; // value native currency sent for trading
  ...
}
```

which can be passed into [ethers signer.sendTransaction](https://docs.ethers.org/v5/api/signer/#Signer-sendTransaction) as follows:

```typescript
signer.sendTransaction({
  to: rebalancing.txHandler,
  data: rebalancing.txData,
  value: rebalancing.txValue,
});
```


---

# 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.31third.com/31third-api/basket-trade-m-n-swap.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.
