# Exchange Webhook

The Exchange Request Webhook is a special webhook that allows you to receive an exchange request on the order you've created. This is a different webhook from the webhook you use to receive on various events like transaction confirmed, transaction created and transaction failed. As a market provider, you must register one Exchange Request Webhook URL to create order and accept any exchange request.

## Create an **Exchange Request Webhook URL**&#x20;

Go to the dashboard and register a webhook URL to receive exchange request through this URL. Once you register a webhook URL, there will be a checkbox beside the URL. Check this box to mark the URL as the exchange request webhook URL.

![](https://688047236-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-Lkdk4Xs4W94VGkZtEN3%2F-M8HbWgotrAAYvSzc11Y%2F-M8Hl5Ys-9yk0utRq14K%2Fimage.png?alt=media\&token=7433ba7c-8bb1-4c0c-a0b1-48b06865a151)

{% hint style="warning" %}
If you unset this checkbox, this will immediately suspend any exchange request webhooks, which means that you will not be able to accept any exchange requests until you recheck this box.
{% endhint %}

## **The Exchange Request**

When an exchange is requested using your order, Gluwa will make a POST request to the exchange webhook URL for the permission to proceed with the exchange. The following request body is sent with the request.

| Attribute                 | Type     | Description                                                                                                                                                                                                                                                                                                                                                                                                                |
| ------------------------- | -------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| ID                        | `UUID`   | ID of the exchange request                                                                                                                                                                                                                                                                                                                                                                                                 |
| EventType                 | `string` | Always "ExchangeRequest"                                                                                                                                                                                                                                                                                                                                                                                                   |
| Type                      | `string` | Always "Webhook"                                                                                                                                                                                                                                                                                                                                                                                                           |
| ResourceID                | `string` | Order ID                                                                                                                                                                                                                                                                                                                                                                                                                   |
| Conversion                | `string` | The [conversion](https://docs.gluwa.com/api/currency-and-conversion-symbols#conversion-symbols) of the exchange.                                                                                                                                                                                                                                                                                                           |
| DestinationAddress        | `string` | The address where the source amount must be sent to.                                                                                                                                                                                                                                                                                                                                                                       |
| SourceAmount              | `string` | The amount in source currency that this order will exchange.                                                                                                                                                                                                                                                                                                                                                               |
| Fee                       | `string` | The fee amount that must be used to create `ReserveTxnSignature`, `ExecuteTxnSignature` and `ReclaimTxnSignature`                                                                                                                                                                                                                                                                                                          |
| Executor                  | `string` | ***Optional.*** Required if the source currency is Gluwacoin currency (ex> `USD-G`, `KRW-G`). The address that will execute the exchange on your behalf. You need this to sign the reserve transaction signature.                                                                                                                                                                                                          |
| ExpiryBlockNumber         | `string` | <p><em><strong>Optional.</strong></em> Required if the source currency is Gluwacoin currency (ex> <code>USD-G</code>, <code>KRW-G</code>). The block number where your reserved funds will expire. You need this to create the reserve transaction signature.</p><p></p><p>After this block number, the exchange will not execute, and you may call reclaim function on the blockchain to release your reserved funds.</p> |
| ReservedFundsAddress      | `string` | ***Optional.*** Required if the source currency is `BTC`. The address where the source amount must be sent to to reserve your funds for the exchange.                                                                                                                                                                                                                                                                      |
| ReservedFundsRedeemScript | `string` | ***Optional.*** Required if the source currency is `BTC`.                                                                                                                                                                                                                                                                                                                                                                  |

{% hint style="info" %}
If you want to verify that the request was actually sent from Gluwa, you can check the veracity of the webhook as shown [here](https://docs.gluwa.com/development/webhooks#checking-the-veracity-of-a-request-using-x-request-signature).
{% endhint %}

After the you receive the webhook receive, you must do the following to accept the exchange request:

1. Return 200 status code as a response to the webhook request. If you return any other response, Gluwa will try to send the same webhook for the maximum of 5 times, before treating the exchange request as declined.

2. Use [PATCH /V1/ExchangeRequest/{ID}](https://docs.gluwa.com/exchange-request#patch-v-1-exchangerequests-id) endpoint to accept the exchange request. If you fail to successfully accept the exchange request within 10 minutes, the exchange request is automatically declined.

If you decline the exchange request for an order 5 times, that order will be canceled automatically.

## **Receiving Exchange Success and Failed Webhooks**

Gluwa will send a webhook when an exchange succeeds or fails. This will be sent to the same webhook URL as the one you use to receive transaction confirmed, transaction created and transaction failed webhooks, **NOT** to the exchange equest webhook URL.

### **ExchangeSuccess Event**

| Attribute            | Type     | Description                                                                                                                                                                                                                                                |
| -------------------- | -------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| EventType            | `string` | Always "ExchangeSuccess"                                                                                                                                                                                                                                   |
| Type                 | `string` | Always "Webhook"                                                                                                                                                                                                                                           |
| ResourceID           | `string` | Order ID                                                                                                                                                                                                                                                   |
| OrderAmountRemaining | `string` | The amount remaining in the order.                                                                                                                                                                                                                         |
| Conversion           | `string` | Conversion symbol for the order. See [conversion](https://docs.gluwa.com/api/currency-and-conversion-symbols#conversion-symbols).                                                                                                                          |
| SendingAddress       | `string` | The address that will fund the source amount.                                                                                                                                                                                                              |
| ReceivingAddress     | `string` | <p>The address that the exchanged currency will be received.</p><p></p><p>For example, if the conversion is <code>BtcUsdg</code>, your receiving address must be a <code>USD-G</code> address since your exchanged funds will be sent to that address.</p> |
| SourceAmount         | `string` | The amount in source currency that this order will exchange.                                                                                                                                                                                               |
| Price                | `string` | The price the order will use for the exchange. The unit is `<exchanged currency>/<source currency>`.                                                                                                                                                       |
| ExchangedAmount      | `string` | The exchanged amount in exchanged currency.                                                                                                                                                                                                                |

### **ExchangeFailed Event**

| Attribute            | Type     | Description                                                                                                                                                                                                                                                |
| -------------------- | -------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| EventType            | `string` | Always "ExchangeFailed"                                                                                                                                                                                                                                    |
| Type                 | `string` | Always "Webhook"                                                                                                                                                                                                                                           |
| ResourceID           | `string` | Order ID                                                                                                                                                                                                                                                   |
| OrderAmountRemaining | `string` | The amount remaining in the order.                                                                                                                                                                                                                         |
| Conversion           | `string` | Conversion symbol for the order. See [conversion](https://docs.gluwa.com/api/currency-and-conversion-symbols#conversion-symbols).                                                                                                                          |
| SendingAddress       | `string` | The address that will fund the source amount.                                                                                                                                                                                                              |
| ReceivingAddress     | `string` | <p>The address that the exchanged currency will be received.</p><p></p><p>For example, if the conversion is <code>BtcUsdg</code>, your receiving address must be a <code>USD-G</code> address since your exchanged funds will be sent to that address.</p> |
| SourceAmount         | `string` | The amount in source currency that this order will exchange.                                                                                                                                                                                               |
| Price                | `string` | The price the order will use for the exchange. The unit is `<exchanged currency>/<source currency>`.                                                                                                                                                       |
| ExchangedAmount      | `string` | The exchanged amount in exchanged currency.                                                                                                                                                                                                                |
