Direct exchange

This guide will explain how to perform a Currency Exchange using the Vault API. You will be able to exchange one currency for another on the user’s account with ease. The process involves creating a request to exchange the source currency for the target currency. --- ## Step 1: Make a Request to Exchange Currency To create a currency exchange, send a POST request to the direct-exchange endpoint. ### Endpoint

Step 1: Make a Request to Exchange Currency

To create a currency exchange, send a POST request to the direct-exchange endpoint.

Query Parameters

ParameterTypeDescription
dryRunbooleanIf true, simulates the exchange and returns the expected rate and fee without performing the exchange.

Body Parameters

The following parameters are required in the request body to initiate the exchange:

ParameterTypeDescription
fromAccountstringThe account initiating the exchange (required).
toAccountstringThe destination account for the exchange (required).
fromCurrencystringThe currency to exchange from (required).
toCurrencystringThe currency to exchange to (required).
fromAmountstringThe amount of the source currency to exchange (required).
toAmountstringThe amount in the target currency that you expect to receive (required).
signedRateobjectThe exchange rate object for the transaction.

signedRate Object

This object contains the rate at which the exchange is executed.

ParameterTypeDescription
rateRequestobjectRequest details for the currency conversion rate.
ratestringThe rate at which the exchange will happen.
validUntilstringThe timestamp until which the rate is valid.
signaturestringThe digital signature for the rate.

Best Practices

  • Use dryRun for Testing:
    Always use dryRun to simulate the exchange and check the rate and fees before performing the actual exchange.

  • Check Expiry Dates:
    Ensure that the exchange rate has not expired by reviewing the validUntil timestamp.

  • Review Fees:
    The exchange will involve a fee (feeAmount). Review it to understand the total cost of the exchange.


Conclusion

This guide explains the process for creating a currency exchange between two accounts using the Vault API. By using the dryRun feature, you can simulate the exchange before committing to the transaction, ensuring you understand the rate and fee structure. Always review the details before performing a live exchange.

For any issues or questions, refer to the official API documentation or contact support for assistance.