How to Use Swap API
Last updated
Last updated
Swap API is the recommended way of interacting with Orion Protocol for retail trade. Under the hood, the API performs three tasks:
Queries prices of ERC20 assets from multiple centralized and decentralized exchanges.
Aggregates the liquidity from the queried sources to provide the best price possible.
Returns the trade in a format that can be easily executed using the Web3 library of your choice.
A is required if you want a third-party to move funds on your behalf. In short, you are allowing them to move your tokens.
In our case, we would like the Orion Exchange contract to trade our ERC20 tokens for us, so we will need to approve an allowance (a certain amount) for this contract to move a certain amount of our ERC20 tokens on our behalf.
When setting the token allowance, make sure to provide enough allowance for the buy or sell amount as well as the gas.
TIP
When setting the token allowance, make sure to provide enough allowance for the buy or sell amount as well as the gas; otherwise, you may receive a 'Gas estimation failed' error.
TODO:
For implementation details, see 'How to set token allowances'
The Swap API provides information about a swap between two different assets. The information includes the amount of the incoming and outgoing assets, price, and alternative paths.
Here are the examples on how to retrieve swap info.