# async

The calculation of rebalancings might take some seconds depending on how many assets are involved. Therefore all rebalancing endpoints have the option to calculate them async. If `async` is set to `true` you receive an `id` for your rebalancing and you can then periodically fetch the progress of the rebalancing. If its done, `percent` will have the value `100` and you will also receive the rebalancing.

## /rebalancing/calculation-progress/{id}

Fetch the current progress or receive the final rebalancing if it's done.

## Get calculation progress

> Returns progress state of running rebalancing

```json
{"openapi":"3.0.0","info":{"title":"31Third Trading API","version":"1.3"},"tags":[{"name":"rebalancing (common)","description":"Execute common rebalancing actions"}],"paths":{"/1.3/rebalancing/calculation-progress/{id}":{"get":{"operationId":"RebalancingCommonController_getCalculationProgress","summary":"Get calculation progress","description":"Returns progress state of running rebalancing","parameters":[{"name":"x-api-key","in":"header","description":"31Third API key (Request via dev@31third.com)","schema":{"type":"string"}},{"name":"id","required":true,"in":"path","schema":{"type":"string"}},{"name":"accept-language","required":true,"in":"header","schema":{"type":"string"}}],"responses":{"200":{"description":"","content":{"application/json":{"schema":{"$ref":"#/components/schemas/CalculationProgressDto"}}}}},"tags":["rebalancing (common)"]}}},"components":{"schemas":{"CalculationProgressDto":{"type":"object","properties":{"percent":{"type":"number","description":"Progress in percent"},"message":{"type":"string","description":"Progress status message or error message"},"failed":{"type":"boolean","description":"Indicates if rebalancing failed"},"rebalancing":{"description":"If finished. Rebalancing result is found here","allOf":[{"$ref":"#/components/schemas/RebalancingResponseDto"}]}},"required":["percent","message","failed","rebalancing"]},"RebalancingResponseDto":{"type":"object","properties":{"id":{"type":"string","description":"Unique ID of the calculated rebalancing."},"creationDate":{"format":"date-time","type":"string","description":"Rebalancing creation timestamp"},"baseValueInUsd":{"type":"number","description":"Total value of assets in the rebalancing base allocation. (in USD)"},"sellValueInUsd":{"type":"number","description":"The proportion of value that is taken out for trades, meaning sold. (in USD)"},"estimatedValueLossInUsd":{"type":"number","description":"Estimated loss of total portfolio value. (in USD; fees are already included in this value)"},"estimatedTargetValueInUsd":{"type":"number","description":"Estimated total value of the rebalancing target allocation. (in USD; fees are already included in this value)"},"estimatedReceiveValueInUsd":{"type":"number","description":"Estimated value of assets received after all trades. (in USD; fees are already included in this value)"},"minReceiveValueInUsd":{"type":"number","description":"Minimal total portfolio value after the rebalancing. (in USD; slippage and fees are included in this value)"},"estimatedImpact":{"type":"number","description":"Estimated impact. (0.01 = 1%; fees are already included in this value)"},"maxImpact":{"type":"number","description":"Maximal impact. (0.01 = 1%; slippage and fees are included in this value)"},"estimatedGasUnits":{"format":"int64","type":"integer","description":"Estimated gas units for this trade. (in WEI)"},"suggestedGasPrice":{"format":"int64","type":"integer","description":"Suggested gas price [LOW/MARKET/AGGRESSIVE] fetched from a block explorer (e.g. Etherscan). (in WEI)"},"estimatedGasFees":{"format":"int64","type":"integer","description":"Estimated gas fees for the rebalancing. (in WEI)"},"estimatedGasFeesInUsd":{"type":"number","description":"Estimated gas fees for the rebalancing. (in USD)"},"estimatedProtocolFeesInUsd":{"type":"number","description":"Estimated protocol fees for the rebalancing. (in USD)"},"requiredAllowances":{"description":"List of tokens for which the allowance has to be increased before executing the rebalancing. (List based on the wallet passed in the rebalancing request.)","type":"array","items":{"$ref":"#/components/schemas/AllowanceDto"}},"trades":{"description":"List of trades which will be executed to fulfill the rebalancing.","type":"array","items":{"$ref":"#/components/schemas/TradeDto"}},"txHandler":{"type":"string","description":"[Just if a batch trade is requested, otherwise use txHandler per trade] Address of the contract to send the txData to. It will be our <b>batch trade</b> contract if it is a rebalancing transaction. However, in some special cases, it may also be a different contract, for example, in the case of wrapping ETH into WETH."},"txData":{"type":"object","description":"[Just if a batch trade is requested, otherwise use txData per trade] Call data to execute the rebalancing. (Must be sent to the <code>txHandler</code> contract address.)"},"txValue":{"format":"int64","type":"integer","description":"Call value to execute the rebalancing. (Must be sent to the <code>txHandler</code> contract address.)"},"tokensWithoutPricePair":{"type":"string","description":"List of tokens for which no price pair could be found."},"executable":{"type":"boolean","description":"Is executable based on wallet permissions for smart contracts"},"expirationTimestamp":{"format":"date-time","type":"string","description":"If the rebalancing contains RFQ/OTC trades this is a hard deadline.If not this can be considered as soft deadline. A new rebalancing should be calculated since after some time market prices might have changed in a way that another composition of trades might be better."},"earliestRefreshQuotesTimestamp":{"format":"date-time","type":"string","description":"Earliest timestamp when quotes for this rebalancing can be refreshed"},"suggestedRefreshQuotesTimestamp":{"format":"date-time","type":"string"},"tenderlySimulation":{"description":"Tenderly simulation result.","allOf":[{"$ref":"#/components/schemas/TenderlySimulationDto"}]}},"required":["id","creationDate","baseValueInUsd","sellValueInUsd","estimatedValueLossInUsd","estimatedTargetValueInUsd","estimatedReceiveValueInUsd","minReceiveValueInUsd","estimatedImpact","maxImpact","estimatedGasUnits","suggestedGasPrice","estimatedGasFees","estimatedGasFeesInUsd","estimatedProtocolFeesInUsd","requiredAllowances","trades","txHandler","txData","txValue","tokensWithoutPricePair","executable","expirationTimestamp","earliestRefreshQuotesTimestamp","suggestedRefreshQuotesTimestamp","tenderlySimulation"]},"AllowanceDto":{"type":"object","properties":{"token":{"description":"Token address that needs allowance","allOf":[{"$ref":"#/components/schemas/SimpleTokenDto"}]},"allowanceTarget":{"type":"string","description":"Exchange proxy to set the allowance on"},"neededAllowance":{"format":"int64","type":"integer","description":"Allowance needed to execute rebalancing"},"currentAllowance":{"format":"int64","type":"integer","description":"Current allowance set on target"},"resetNeeded":{"type":"boolean","description":"Reset allowance to 0 before setting new one"}},"required":["token","allowanceTarget","neededAllowance","currentAllowance","resetNeeded"]},"SimpleTokenDto":{"type":"object","properties":{"address":{"type":"string","description":"Address of the token"},"name":{"type":"string","description":"Name of the token"},"symbol":{"type":"string","description":"Symbol of the token"},"imageUrl":{"type":"string","description":"Url of the token icon"},"decimals":{"type":"number","description":"Decimals of the token"},"sliderColor":{"type":"string","description":"Color based on the icon that can be used for elements in the frontend"},"chain":{"description":"Chain on which the token is deployed","allOf":[{"$ref":"#/components/schemas/ChainDto"}]},"tags":{"description":"Tags categorizing the token","type":"array","items":{"type":"string"}},"deflationary":{"type":"boolean","description":"Describes if this token is deflationary (e.g.: transfer fees)"}},"required":["address","name","symbol","imageUrl","decimals","sliderColor","chain","tags","deflationary"]},"ChainDto":{"type":"object","properties":{"name":{"type":"string","description":"Name of the chain"},"identifier":{"type":"string","description":"ID of the EVM base chain as hex value"},"enabled":{"type":"boolean","description":"Describes if rebalancings are enabled"},"batchTradeSupported":{"type":"boolean","description":"Describes if batch trade is supported"},"batchTradeAddress":{"type":"string","description":"Address of the deployed 31third-protocol BatchTrade contract"},"blockExplorerLink":{"type":"string","description":"Link of the most common block explorer"},"nativeTokenAddress":{"type":"string","description":"(Pseudo)-address of the chains native token"},"wrappedNativeTokenAddress":{"type":"string","description":"Address of the chains wrapped native token"},"tokenHelperAddress":{"type":"string","description":"Address of a helper contract capable of doing batch reads"},"portfolioEnabled":{"type":"boolean","description":"Describes if portfolio feature is enabled"}},"required":["name","identifier","enabled","batchTradeSupported","batchTradeAddress","blockExplorerLink","nativeTokenAddress","wrappedNativeTokenAddress","tokenHelperAddress","portfolioEnabled"]},"TradeDto":{"type":"object","properties":{"from":{"description":"Sell token.","allOf":[{"$ref":"#/components/schemas/SimpleTokenDto"}]},"to":{"description":"Receive token.","allOf":[{"$ref":"#/components/schemas/SimpleTokenDto"}]},"fromAmount":{"format":"int64","type":"integer","description":"Amount of the <code>from</code> token to sell. (In from token units)"},"toAmount":{"format":"int64","type":"integer","description":"Amount of the <code>to</code> token to receive. (In to token units; liquidity source fees are already included in this value)"},"minToReceiveBeforeFees":{"format":"int64","type":"integer","description":"Minimal amount of the <code>to</code> token to receive excluding fees. (In to token units; slippage and liquidity source fees are included in this value; protocol fees are excluded)"},"minToReceive":{"format":"int64","type":"integer","description":"Minimal amount of the <code>to</code> token to receive. (In to token units; slippage, liquidity source fees and protocol fees are included in this value)"},"fromValueInUsd":{"type":"number","description":"Value of the <code>from</code> token to sell. (in USD)"},"toValueInUsd":{"type":"number","description":"Value of the <code>to</code> token to receive. (in USD; liquidity source fees are already included in this value)"},"minToReceiveBeforeFeesInUsd":{"type":"number","description":"Minimal amount of the <code>to</code> token to receive excluding fees. (In USD; slippage and liquidity source fees are included in this value; protocol fees are excluded)"},"minToReceiveInUsd":{"type":"number","description":"Minimal value of the <code>to</code> token to receive. (in USD; slippage, liquidity source fees and protocol fees are included in this value)"},"estimatedPriceImpact":{"type":"number","description":"Estimated price impact in percent. [-1;1]. > 0 = value loss. < 0 = value gain","minimum":-1,"maximum":1},"maxSlippage":{"type":"number","description":"Maximum allowed slippage used for the calculation of this trade. (0.01 = 1%)","minimum":0,"default":0.005,"maximum":1},"price":{"type":"number","description":"Price of the <code>to</code> token in <code>from</code> token. Does not included slippage."},"guaranteedPrice":{"type":"number","description":"Guaranteed price of the <code>to</code> token in <code>from</code> token including slippage."},"previouslyRequiredTrades":{"description":"List of IDs of the trades that have to be executed before this trade.","type":"array","items":{"type":"string"}},"allowanceTarget":{"type":"string","description":"Allowance target to set the allowance to if <code>allowanceNeeded</code> is <code>true</code>"},"estimatedGasUnits":{"format":"int64","type":"integer","description":"Estimated gas units for this trade. (in WEI)"},"suggestedGasPrice":{"format":"int64","type":"integer","description":"Suggested gas price [LOW/MARKET/AGGRESSIVE] fetched from a block explorer (e.g. Etherscan). (in WEI)"},"estimatedGasFees":{"format":"int64","type":"integer","description":"Estimated gas fees for this trade [estimatedGasUnits * suggestedGasPrice]. (in WEI)"},"estimatedFees":{"format":"int64","type":"integer","deprecated":true,"description":"[USE estimatedGasFees INSTEAD] Estimated gas fees for this trade [estimatedGasUnits * suggestedGasPrice]. (in WEI)"},"expirationTimestamp":{"format":"date-time","type":"string","description":"Shows an approximate expiration estimation for this trade. When a trade is expired, <code>/rebalancing/refresh-expired-quotes</code> can be used to refresh the quote for this trade. Alternatively, a new rebalancing can be calculated."},"transactions":{"type":"array","items":{"type":"string"}},"fill":{"$ref":"#/components/schemas/FillDto"}},"required":["from","to","fromAmount","toAmount","minToReceiveBeforeFees","minToReceive","fromValueInUsd","toValueInUsd","minToReceiveBeforeFeesInUsd","minToReceiveInUsd","estimatedPriceImpact","maxSlippage","price","guaranteedPrice","previouslyRequiredTrades","allowanceTarget","estimatedGasUnits","suggestedGasPrice","estimatedGasFees","estimatedFees","expirationTimestamp","transactions","fill"]},"FillDto":{"type":"object","properties":{"liquiditySource":{"$ref":"#/components/schemas/SimpleLiquiditySourceDto"},"proportionInBps":{"type":"number"},"from":{"$ref":"#/components/schemas/SimpleTokenDto"},"to":{"$ref":"#/components/schemas/SimpleTokenDto"},"subFills":{"type":"array","items":{"type":"string"}}},"required":["liquiditySource","proportionInBps","from","to","subFills"]},"SimpleLiquiditySourceDto":{"type":"object","properties":{"identifier":{"type":"string"},"readableName":{"type":"string"},"iconUrl":{"type":"string"},"enabled":{"type":"boolean"}},"required":["identifier","readableName","iconUrl","enabled"]},"TenderlySimulationDto":{"type":"object","properties":{"status":{"type":"boolean","description":"Simulation status. True if tx simulation succeeded, false otherwise."},"errorMessage":{"type":"string","description":"Error message. Just present if <code>status</code> is <code>false</code>."},"blockNumber":{"type":"number","description":"Block number used for the simulation."},"gas":{"format":"int64","type":"integer","description":"Amount of gas provided for the simulation."},"gasUsed":{"format":"int64","type":"integer","description":"Amount of gas used for the simulation."}},"required":["status","errorMessage","blockNumber","gas","gasUsed"]}}}}
```

## /rebalancing/cancel/{id}

Cancel the calculation of a requested rebalancing.

## Cancel rebalancing

> Cancel async rebalancing with id

```json
{"openapi":"3.0.0","info":{"title":"31Third Trading API","version":"1.3"},"tags":[{"name":"rebalancing (common)","description":"Execute common rebalancing actions"}],"paths":{"/1.3/rebalancing/cancel/{id}":{"get":{"operationId":"RebalancingCommonController_cancelRebalancing","summary":"Cancel rebalancing","description":"Cancel async rebalancing with id","parameters":[{"name":"x-api-key","in":"header","description":"31Third API key (Request via dev@31third.com)","schema":{"type":"string"}},{"name":"walletAddress","required":true,"in":"query","schema":{"type":"string"}},{"name":"id","required":true,"in":"path","schema":{"type":"string"}}],"responses":{"200":{"description":""}},"tags":["rebalancing (common)"]}}}}
```


---

# 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/async.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.
