Learn how to swap crypto to fiat and vice versa using our public API
Swapping between different currencies can easily be done using 0xpay Exchange API.
In order to make an exchange, you'll need to account for several factors:
- Supported exchange pairs – some trading pairs might not be available, be sure to check for them.
- Price Volatility – due to extreme volatility in crypto markets, exchange price estimate is fixed for 10 seconds. If you wait longer than 10 seconds before executing an exchange, it might fail due to price change.
- Liquidity & fees – while you can always set your own fees for exchange operations, it is necessary to maintain enough liquidity for swap fees on your merchant balance.
- 1.User wants to exchange 100 USDT to ETH on your platform. In order to check if the exchange pair is supported, your system sends a Get Available Exchange Directions request to 0xpay API.
- 2.In response, 0xpay API will send a list of all trading pairs, along with info about min/max amounts to exchange.
- 3.After confirming the trading pair, user inputs the amount to exchange and presses "Calculate" button on your website. At this point your system needs to make a request to Estimate Exchange endpoint in order to receive actual price and exchange fee.
- 4.0xpay calculates exchange parameters and responds with a notification to your platform. You can display these parameters (exchange rate, pair, fees) on the platform for the users to acknowledge.
- 5.When user presses the Exchange button, your system will send a request to Create Exchange operation endpoint.
- 6.0xpay creates an exchange operation and notifies you about status of the exchange.
- 7.After status changes to "Done", you can go ahead and modify user's balances on the platform!