# Swap Order

This endpoint is called when a customer wants to make either a fiat-fiat or crypto-crypto swap for currencies.

It is an `POST` endpoint that takes your `secretKey` as a required parameter in the Header which verifies the integrity of your third-party application.

Your request should contain properties like the customer's email, phone number, customer deposit, and receipt methods, etc. See the example below;

## Initates a swap order

<mark style="color:green;">`POST`</mark> `https://canary.xendbridge.com/api/peertopeerorder/swap/initiate`

#### Headers

| Name                                        | Type   | Description       |
| ------------------------------------------- | ------ | ----------------- |
| secretKey<mark style="color:red;">\*</mark> | string | {your\_secretKey} |

#### Request Body

| Name                                                        | Type    | Description                                |
| ----------------------------------------------------------- | ------- | ------------------------------------------ |
| email<mark style="color:red;">\*</mark>                     | string  | <annadoe@gmail.com>                        |
| phoneNumber                                                 | string  | 07012345678                                |
| userName                                                    | string  | annadoe                                    |
| payInCurrencyCode<mark style="color:red;">\*</mark>         | string  | BUSD                                       |
| payInCurrencyNetwork<mark style="color:red;">\*</mark>      | string  | BEP20                                      |
| receieveInCurrencyCode<mark style="color:red;">\*</mark>    | string  | USDT                                       |
| receieveInCurrencyNetwork<mark style="color:red;">\*</mark> | string  | POLYGON                                    |
| orderAmount<mark style="color:red;">\*</mark>               | decimal | 50                                         |
| consumerDepositMethod                                       | object  |                                            |
| paymentMethod<mark style="color:red;">\*</mark>             | string  | Crypto                                     |
| paymentData                                                 | object  |                                            |
| consumerReceiptMethod                                       | object  |                                            |
| paymentMethod<mark style="color:red;">\*</mark>             | string  | Crypto                                     |
| paymentData                                                 | object  |                                            |
| walletAddress<mark style="color:red;">\*</mark>             | String  | 0x52434Ac4BE04393e020c9b16C327d04d4367Cbcd |
| network<mark style="color:red;">\*</mark>                   | string  | POLYGON                                    |
| walletAddress                                               | string  | 0x52434Ac4BE04393e020c9b16C327d04d4367Cbcd |
| network                                                     | string  | BEP-20                                     |

{% tabs %}
{% tab title="200: OK Success" %}

```json
{
    "data": {
        "orderReference": "XC_460ed3181a9b48a089bac1af671146d1",
        "receiveInCurrencyCode": "WNT",
        "payInCurrencyCode": "BUSD",
        "receivableAmount": 4.52285,
        "payableAmount": 50,
        "receivableAmountWithoutMarkup": 0,
        "providerName": "John Doe",
        "providerFirstName": "John",
        "providerLastName": "Doe",
        "providerEmail": "owolabidamilola98@gmail.com",
        "initiatedAt": "2022-11-15T11:46:02.1799889Z",
        "orderExpiryDate": "2022-11-15T11:53:02.1212106Z",
        "initiatedAtTimestamp": 1668512762121,
        "orderExpiryTimestamp": 1668513182121,
        "estimatedOrderCompletionTimestamp": null,
        "fundedProviderAtTimeStamp": null,
        "fundedCustomerAtTimeStamp": null,
        "orderCompletedAtTimeStamp": null,
        "p2POrderStatus": "Acknowledged",
        "disputeStatus": "NoDispute",
        "disputeReference": null,
        "orderType": "Swap",
        "providerContact": {
            "phoneNumber": "2348181186644",
            "whatsappNumber": ""
        },
        "customerContact": {
            "email": "annadoe@gmail.com",
            "name": "annadoe",
            "phoneNumber": "07064366723"
        },
        "providerPaymentMethods": {
            "paymentMethod": "Crypto",
            "paymentType": "Crypto",
            "paymentData": [
                {
                    "walletAddress": "0xB13A251A67E7f7e7466758EF55A3aDD69A7C15A3",
                    "network": "BEP20",
                    "currency": "BUSD"
                }
            ],
            "orderPaymentMethod": {
                "walletAddress": "0xB13A251A67E7f7e7466758EF55A3aDD69A7C15A3",
                "network": "BEP20",
                "currency": "BUSD"
            }
        },
        "consumerDepositMethod": {
            "paymentMethod": "Crypto",
            "paymentType": 0,
            "paymentData": {
                "walletAddress": "0x30b7D85f7CF498D556a9448243a7994bc4660790",
                "network": "BEP20",
                "currency": "BUSD"
            }
        },
        "consumerReceiptMethod": {
            "paymentMethod": "Crypto",
            "paymentType": 0,
            "paymentData": {
                "walletAddress": "0x30b7D85f7CF498D556a9448243a7994bc4660790",
                "network": "POLYGON",
                "currency": "WNT"
            }
        },
        "markupDetail": null,
        "providerTransactionMetadata": null,
        "customerTransactionMetadata": null
    },
    "status": "OK",
    "message": ""
}
```

{% endtab %}

{% tab title="400: Bad Request Iniating another buy order while one is not finished is not allowed." %}

```json
{
    "Status": 2,
    "Message": "You Have A Pending Swap Order",
    "Data": null
}
```

{% endtab %}
{% endtabs %}

<details>

<summary>Crypto-Crypto JSON Request Format</summary>

```json
{
  "emailAddress": "annadoe@gmail.com",
  "phoneNumber": "07064366723",
  "userName": "annadoe",
  "payInCurrencyCode": "BUSD",
  "payInCurrencyNetwork": "BEP20",
  "receiveInCurrencyCode": "WNT",
  "receiveInCurrencyNetwork": "POLYGON",
  "orderAmount": 50,
  "consumerDepositMethod": {
    "paymentMethod": "Crypto",
    "paymentData": {
      "walletAddress": "0x30b7D85f7CF498D556a9448243a7994bc4660790",
      "network": "BEP20"
    }
  },
  "consumerReceiptMethod": {
    "paymentMethod": "Crypto",
    "paymentData": {
      "walletAddress": "0x30b7D85f7CF498D556a9448243a7994bc4660790",
      "network": "POLYGON"
    }
  }
}
```

</details>

<details>

<summary>Fiat-Fiat JSON Request Format</summary>

```json
{
  "emailAddress": "annadoe@gmail.com",
  "phoneNumber": "07064366723",
  "userName": "annadoe",
  "payInCurrencyCode": "BUSD",
  "payInCurrencyNetwork": "BEP20",
  "receiveInCurrencyCode": "WNT",
  "receiveInCurrencyNetwork": "POLYGON",
  "orderAmount": 50,
  "consumerDepositMethod": {
    "paymentMethod": "Bank",
    "paymentData": {
      "accountName": "Anna Doe",
      "accountNumber": "0000187849",
      "bankName": "Access Bank"
    }
  },
  "consumerReceiptMethod": {
    "paymentMethod": "Bank",
    "paymentData": {
      "accountName": "Anna Doe",
      "accountNumber": "0000187849",
      "bankName": "Access Bank"
    }
  }
}
```

</details>

{% tabs %}
{% tab title="Request Field" %}

| Parameter             | Type    | Definitions                                                                                                      |
| --------------------- | ------- | ---------------------------------------------------------------------------------------------------------------- |
| emailAddress          | string  | `Required` This is the consumer's email address.                                                                 |
| phoneNumber           | string  | `Required` This is the consumer's phone number.                                                                  |
| userName              | string  | `Required` This is the consumer's username                                                                       |
| payInCurrencyCode     | enum    | `Required` This is the currency code to pay with. Must be `BUSD` for sell order.                                 |
| receiveInCurrencyCode | enum    | `Required` This is the currency code to receive the currency in. Must be `NGN` for buy order.                    |
| orderAmount           | decimal | `Required` The order amount by the consumer.                                                                     |
| consumerDepositMethod | object  | `Required` This holds the properties of the deposit method of the consumer.                                      |
| paymentMethod         | enum    | `Required` The payment method by which transactions are made. It should be `CRYPTO`for sell order.               |
| paymentData           | object  | `Required` This holds the properties of the wallet details of the consumer.                                      |
| walletAddress         | string  | `Required` The crypto wallet address of the consumer.                                                            |
| network               | enum    | `Required` This is the network on which the address is on. It could be `BEP20`, `ERC20` or `POLYGON`.            |
| consumerReceiptMethod | object  | `Required` This holds the properties of the consumer receiving method. The `paymentMethod` prop must be `Bank` . |
| paymentData           | object  | `Required` This holds the properties of the consumer receiving bank account details.                             |
| accountName           | string  | `Required` This is the account name of the consumer.                                                             |
| accountNumber         | string  | `Required` The local bank account number of the consumer                                                         |
| bankName              | string  | `Required` This is the bank name of the consumer.                                                                |
| {% endtab %}          |         |                                                                                                                  |

{% tab title="Response Fields" %}

<table><thead><tr><th width="209.94541484716154">Parameter</th><th width="150">Type</th><th>Definitions</th></tr></thead><tbody><tr><td>orderReference</td><td>string</td><td>This the reference to a particular order.</td></tr><tr><td>receiveInCurrencyCode</td><td>enum</td><td>This is the currency code to receive the currency in.</td></tr><tr><td>payInCurrencyCode</td><td>enum</td><td>This is the currency code to pay with.</td></tr><tr><td>receivableAmount</td><td>decimal</td><td>This the receivable amount of the currency.</td></tr><tr><td>payableAmount</td><td>decimal</td><td>This is the payable amount of the currency.</td></tr><tr><td>providerName</td><td>string</td><td>This the provider's name.</td></tr><tr><td>providerFirstName</td><td>string</td><td>This is the provider's first name.</td></tr><tr><td>providerLastName</td><td>string</td><td>This is the provider's last name.</td></tr><tr><td>providerEmail</td><td>string</td><td>This is the provider's email address.</td></tr><tr><td>initiatedAt</td><td>DateTime</td><td>The date time the order was made.</td></tr><tr><td>orderExpiryDate</td><td>DateTime</td><td>The expiry date time of the order.</td></tr><tr><td>initiatedAtTimestamp</td><td>long</td><td>The time in milliseconds an order was made</td></tr><tr><td>orderExpiryTimestamp</td><td>long</td><td>The time in milliseconds of when thee order will expire.</td></tr><tr><td>fundedProviderAtTimeStamp</td><td>long</td><td>The time of when a customer indicates payment for an order in milliseconds.</td></tr><tr><td>fundedCustomerAtTimeStamp</td><td>long</td><td>The time of when a provider indicates payment of order to the customer in milliseconds</td></tr><tr><td>orderCompletedAtTimeStamp</td><td>long</td><td>The time in milliseconds an order was completed.</td></tr><tr><td>p2POrderStatus</td><td>enum</td><td>The status of the order at the curent time. It could be <code>Submitted</code>, <code>Cancelled</code>, <code>Acknowledged</code>, <code>FundedProvider</code>, <code>FundReceivedFromUser</code>, <code>FundedUser</code>, <code>Completed</code>, <code>OrderTimedOut</code></td></tr><tr><td>disputeStatus</td><td>enum</td><td>The status of the dispute on an order. It could either be <code>NoDispute</code>, <code>DisputeRaisedByCustomer</code>, <code>DisputeRaisedByProvider</code>, <code>DisputeRaisedByBothParties</code>, <code>DisputeResolved</code>or <code>CouldNotBeResolved</code>.</td></tr><tr><td>orderType</td><td>enum</td><td>This is the status of the order, whether it's a <code>Buy</code> or <code>Sell</code>.</td></tr><tr><td>providerContact</td><td>object</td><td>This is holds props of a provider's contact information.</td></tr><tr><td>phoneNumber</td><td>string</td><td>The phone number of either the provider or customer.</td></tr><tr><td>whatsappNumber</td><td>string</td><td>The whatsapp number of either the provider or customer.</td></tr><tr><td>customerContact</td><td>object</td><td>This holds the props of the contact information.</td></tr><tr><td>email</td><td>string</td><td>This is an email address of the customer.</td></tr><tr><td>name</td><td>string</td><td>This is the name of the customer.</td></tr><tr><td>phoneNumber</td><td>string</td><td>The phone number of the customer</td></tr><tr><td>providerPaymentMethods</td><td>object</td><td>This holds the props of the payment methods of the provider.</td></tr><tr><td>paymentMethod</td><td>enum</td><td>This is the method of payment. It could be <code>Bank</code> or <code>Crypto</code></td></tr><tr><td>paymentType</td><td>enum</td><td>This is the type of payment. It could be <code>Bank</code>, <code>Crypto</code>, <code>UserName</code>or <code>MobileMoney</code>.</td></tr><tr><td>paymentData</td><td>object</td><td>This holds the props of the payment method.</td></tr><tr><td>bankName</td><td>string</td><td>The bank name of the the provider or customer.</td></tr><tr><td>accountNumber</td><td>string</td><td>The bank account number of the provider or customer.</td></tr><tr><td>accountName</td><td>string</td><td>The bank account name of the provider or customer.</td></tr><tr><td>currency</td><td>enum</td><td>The currency in which the order was made. It could be <code>BUSD</code> or <code>NGN</code>.</td></tr><tr><td>orderPaymentMethod</td><td>object</td><td>This holds props of the payment method in which the order is to be made to.</td></tr><tr><td>consumerDepositMethod</td><td>object</td><td>This holds the props of the consumer deposit details.</td></tr><tr><td>consumerrReceiptMethod</td><td>object</td><td>This holds the props of the consumer receiving method details.</td></tr><tr><td>walletAddress</td><td>string</td><td>This is the crypto wallet address of the consumer.</td></tr><tr><td>network</td><td>enum</td><td>This is the network currently supported in the system which the wallet address is based on.</td></tr><tr><td>providerTransactionMetadata</td><td>o</td><td>This holds the props of the transaction metadata of an order.</td></tr></tbody></table>

{% endtab %}
{% endtabs %}


---

# 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://doc.xendbridge.com/api-method-calls/third-party-order-operations/swap-order.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.
