31Third.
Search
K

Rebalancing

Calculate a rebalancing by passing a base allocation (tokens + amounts) and a target allocation (tokens + percentages). Additional options are shown in the following request documentation:
post
/0.1/rebalancing
Request a rebalancing for an arbitrary set of tokens

Sell tokens are passed with amounts, buy tokens are passed as percentage allocation

Parameters
Header
chain-id
string
Chain ID as hex string. (e.g.: 0x1 for Ethereum mainnet)
x-api-key
string
API key
Body
Example
Schema
{
"walletAddress": "0xAb5801a7D398351b8bE11C439e05C5B3259aeC9B",
"maxDeviationFromTarget": 0.005,
"maxSlippage": 0.01,
"excludedSources": [
"Kyber",
"Dodo",
"CryptoCom"
],
"automatedMarketMakerEnabled": true,
"rfqtEnabled": true,
"batchTrade": false,
"revertOnError": true,
"failOnMissingPricePair": true,
"baseEntries": [
{
"tokenAddress": "0xdac17f958d2ee523a2206206994597c13d831ec7",
"amount": {
"type": "BigNumber",
"hex": "0xf6e9e1bbe3c000"
}
}
],
"targetEntries": [
{
"tokenAddress": "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48",
"allocation": 0.2
}
]
}
Responses
200: OK

Usage example with ethers.js

The API returns a DTO containing the following properties:
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 as follows:
signer.sendTransaction({
to: rebalancing.txHandler,
data: rebalancing.txData,
value: rebalancing.txValue,
});