# Exchange + Withdrawal

{% hint style="warning" %}
Every request listed on this page requires [authorization](broken://pages/dtfqhMod9SYIPU0fzM4x) to be successfully completed.&#x20;
{% endhint %}

{% hint style="info" %}
Feature currently in **beta**
{% endhint %}

## Estimate Crypto Exchange+Withdrawal

<mark style="color:blue;">`GET`</mark> `https://public.api.0xpay.app/merchants/exchange/withdrawals/crypto/estimate`

You can use this endpoint to estimate your withdrawal with exchange for later [creation](#post-create-exchange)

#### Query Parameters

| Name                                          | Type   | Description                                                                                                                                                                                                                                                                                                                                                                                    |
| --------------------------------------------- | ------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| ticker<mark style="color:red;">\*</mark>      | string | <p><strong>Ticker for withdrawal.</strong></p><p>Example: You want to spend (exchange) USDT and make a withdrawal in <strong>BTC (ticker value)</strong>.</p><p>Find values using <a data-mention href="/pages/f4pta1OrCzRaTuWvgkEi#list-all-supported-crypto-assets">/pages/f4pta1OrCzRaTuWvgkEi#list-all-supported-crypto-assets</a> </p>                                                    |
| spendTicker<mark style="color:red;">\*</mark> | string | <p>Ticker you want to spend (exchange) from your balance.</p><p>Find values using <a data-mention href="/pages/f4pta1OrCzRaTuWvgkEi#list-all-supported-crypto-assets">/pages/f4pta1OrCzRaTuWvgkEi#list-all-supported-crypto-assets</a> or <a data-mention href="/pages/EiL49iurLQydZGUemYNu#list-all-supported-fiat-assets">/pages/EiL49iurLQydZGUemYNu#list-all-supported-fiat-assets</a></p> |
| amount<mark style="color:red;">\*</mark>      | string | Amount you want to **spend** or **withdraw**. For more details look at side field in this request.                                                                                                                                                                                                                                                                                             |
| side<mark style="color:red;">\*</mark>        | string | <p><strong>"spend"</strong> or <strong>"withdraw"</strong>.<br>Impacts <em>amount</em> field. When you want to withdraw the exact amount – specify the "withdraw" side. When you want to spend (exchange) an exact amount specify "exchange" </p>                                                                                                                                              |
| blockchain<mark style="color:red;">\*</mark>  | string | available values you can find [here](/general/networks-and-assets.md#blockchains) ("API value" column)                                                                                                                                                                                                                                                                                         |

{% tabs %}
{% tab title="200: OK Exchange estimate calculated" %}
In response, you'll get details for your upcoming exchange:&#x20;

{% code overflow="wrap" %}

```javascript
{
    "withdraw": {
        "ticker": "USDT", //ticker you want to withdraw after exchange
        "amount": "1493.32" //amount you want to withdraw
        "fee": "123" //withdraw fee, included in withdraw.amount
    },
    "spend": {
        "ticker": "ETH", //ticker you want to spend
        "amount": "1" //amount you want to spend from your balance
    },
    "exchange": {
      "amount": "0.9", // amount to be exchanged
      "fee": "0.1" //exchange fee, included in spend.amount
    },
    "price": {
        "value": "1534.00000000", //actual price of the pair                                
        "pair": [
            "ETH",        //1 ETH == 1534 USDT
            "USDT"
        ]
    },
}
```

{% endcode %}
{% endtab %}

{% tab title="400: Bad Request Description of error codes" %}
{% code overflow="wrap" %}

```javascript
//List of Error codes with descriptions
//0 – Order validation error
//1 – Ticker pair not allowed
//2 – Withdraw amount too low
//3 – Not enough liquidity
{
    "code": 1,
    "description": "Ticker pair not allowed"
}
```

{% endcode %}
{% endtab %}
{% endtabs %}

## Create Crypto Exchange+Withdrawal

<mark style="color:green;">`POST`</mark> `https://public.api.0xpay.app/merchants/exchange/withdrawals/crypto`

This endpoint is used to create exchange withdrawal. Before sending this request, you should first [estimate your exchange+withdrawal using the endpoint](#get-estimate-crypto-exchange-withdrawal).

**Status Notifications:** After the **Success** response, 0xpay API will produce [notifications](/public-api/notifications.md#exchange) according to status updates on your exchange.

#### Request Body

| Name                                          | Type   | Description                                                                                                                                                                                                                                                                                                                                                                                    |
| --------------------------------------------- | ------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| ticker<mark style="color:red;">\*</mark>      | string | <p><strong>Ticker for withdrawal.</strong></p><p>Example: You want to spend (exchange) USDT and make a withdrawal in <strong>BTC (ticker value)</strong>.</p><p>Find values using <a data-mention href="/pages/f4pta1OrCzRaTuWvgkEi#list-all-supported-crypto-assets">/pages/f4pta1OrCzRaTuWvgkEi#list-all-supported-crypto-assets</a> </p>                                                    |
| amount<mark style="color:red;">\*</mark>      | string | Amount you want to **spend** or **withdraw**. For more details look at side field in this request.                                                                                                                                                                                                                                                                                             |
| side<mark style="color:red;">\*</mark>        | string | <p><strong>"spend"</strong> or <strong>"withdraw"</strong>.<br>Impacts <em>amount</em> field. When you want to withdraw the exact amount – specify the "withdraw" side. When you want to spend (exchange) an exact amount specify "exchange" </p>                                                                                                                                              |
| fee<mark style="color:red;">\*</mark>         | string | withdrawal fee                                                                                                                                                                                                                                                                                                                                                                                 |
| price<mark style="color:red;">\*</mark>       | string | actual price of the pairs                                                                                                                                                                                                                                                                                                                                                                      |
| localId                                       | string | if was specified error will be thrown if not unique, can be useful on your side to avoid the [double-spend](https://en.wikipedia.org/wiki/Double-spending) issue                                                                                                                                                                                                                               |
| meta                                          | string | metadata that you can define and catch it back later with notification                                                                                                                                                                                                                                                                                                                         |
| blockchain<mark style="color:red;">\*</mark>  | string | available values you can find [here](/general/networks-and-assets.md#blockchains) ("API value" column)                                                                                                                                                                                                                                                                                         |
| to<mark style="color:red;">\*</mark>          | string | destination of withdrawal                                                                                                                                                                                                                                                                                                                                                                      |
| spendTicker<mark style="color:red;">\*</mark> | String | <p>Ticker you want to spend (exchange) from your balance.</p><p>Find values using <a data-mention href="/pages/f4pta1OrCzRaTuWvgkEi#list-all-supported-crypto-assets">/pages/f4pta1OrCzRaTuWvgkEi#list-all-supported-crypto-assets</a> or <a data-mention href="/pages/EiL49iurLQydZGUemYNu#list-all-supported-fiat-assets">/pages/EiL49iurLQydZGUemYNu#list-all-supported-fiat-assets</a></p> |
| exchangeFee<mark style="color:red;">\*</mark> | string | fee for exchange operation                                                                                                                                                                                                                                                                                                                                                                     |

{% tabs %}
{% tab title="200: OK Exchange + Withdrawal has been created successfully" %}
{% code overflow="wrap" %}

```javascript
{
    "id": "123e4567-e89b-12d3-a456-426614174000" //internal ID has been assigned to the transaction
}
```

{% endcode %}
{% endtab %}
{% endtabs %}

## Estimate Fiat Exchange+Withdrawal

<mark style="color:blue;">`GET`</mark> `https://public.api.0xpay.app/merchants/exchange/withdrawals/fiat/estimate`

You can use this endpoint to estimate your withdrawal with exchange for later [creation](#post-create-exchange)

#### Query Parameters

| Name                                          | Type   | Description                                                                                                                                                                                                                                                                                                                                                                                    |
| --------------------------------------------- | ------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| ticker<mark style="color:red;">\*</mark>      | string | <p><strong>Ticker for withdrawal.</strong></p><p>Example: You want to spend (exchange) USDT and make a withdrawal in <strong>BTC (ticker value)</strong>.</p><p>Find values using <a data-mention href="/pages/EiL49iurLQydZGUemYNu#list-all-supported-fiat-assets">/pages/EiL49iurLQydZGUemYNu#list-all-supported-fiat-assets</a></p>                                                         |
| spendTicker<mark style="color:red;">\*</mark> | string | <p>Ticker you want to spend (exchange) from your balance.</p><p>Find values using <a data-mention href="/pages/f4pta1OrCzRaTuWvgkEi#list-all-supported-crypto-assets">/pages/f4pta1OrCzRaTuWvgkEi#list-all-supported-crypto-assets</a> or <a data-mention href="/pages/EiL49iurLQydZGUemYNu#list-all-supported-fiat-assets">/pages/EiL49iurLQydZGUemYNu#list-all-supported-fiat-assets</a></p> |
| amount<mark style="color:red;">\*</mark>      | string | Amount you want to **spend** or **withdraw**. For more details look at side field in this request.                                                                                                                                                                                                                                                                                             |
| side<mark style="color:red;">\*</mark>        | string | <p><strong>"spend"</strong> or <strong>"withdraw"</strong>.<br>Impacts <em>amount</em> field. When you want to withdraw the exact amount – specify the "withdraw" side. When you want to spend (exchange) an exact amount specify "exchange" </p>                                                                                                                                              |
| blockchain<mark style="color:red;">\*</mark>  | string | available values you can find [here](/general/networks-and-assets.md#blockchains) ("API value" column)                                                                                                                                                                                                                                                                                         |

{% tabs %}
{% tab title="200: OK Exchange estimate calculated" %}
In response, you'll get details for your upcoming exchange:&#x20;

{% code overflow="wrap" %}

```javascript
{
    "withdraw": {
        "ticker": "UAH", //ticker you want to withdraw after exchange
        "amount": "32" //amount you want to withdraw
        "fee": "10.20213" //withdraw fee, included in withdraw.amount
    },
    "spend": {
        "ticker": "USDT", //ticker you want to spend
        "amount": "1" //amount you want to spend from your balance
    },
    "exchange": {
      "amount": "0.9", // amount to be exchanged
      "fee": "0.1" //exchange fee, included in spend.amount
    },
    "price": {
        "value": "32.000", //actual price of the pair                                
        "pair": [
            "USDT",        //1 USDT == 32 UAH
            "UAH"
        ]
    },
}
```

{% endcode %}
{% endtab %}

{% tab title="400: Bad Request Description of error codes" %}
{% code overflow="wrap" %}

```javascript
//List of Error codes with descriptions
//0 – Order validation error
//1 – Ticker pair not allowed
//2 – Withdraw amount too low
//3 – Not enough liquidity
{
    "code": 1,
    "description": "Ticker pair not allowed"
}
```

{% endcode %}
{% endtab %}
{% endtabs %}

## Create Fiat Exchange+Withdrawal

<mark style="color:green;">`POST`</mark> `https://public.api.0xpay.app/merchants/exchange/withdrawals/fiat`

This endpoint is used to create exchange withdrawal. Before sending this request, you should first [estimate your exchange+withdrawal using the endpoint](#get-estimate-crypto-exchange-withdrawal).

**Status Notifications:** After the **Success** response, 0xpay API will produce [notifications](/public-api/notifications.md#exchange) according to status updates on your exchange.

#### Request Body

| Name                                          | Type   | Description                                                                                                                                                                                                                                                                                                                                                                                    |
| --------------------------------------------- | ------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| ticker<mark style="color:red;">\*</mark>      | string | <p><strong>Ticker for withdrawal.</strong></p><p>Example: You want to spend (exchange) USDT and make a withdrawal in UAH <strong>(ticker value)</strong>.</p><p>Find values using <a data-mention href="/pages/EiL49iurLQydZGUemYNu#list-all-supported-fiat-assets">/pages/EiL49iurLQydZGUemYNu#list-all-supported-fiat-assets</a> request</p>                                                 |
| amount<mark style="color:red;">\*</mark>      | string | Amount you want to **spend** or **withdraw**. For more details look at side field in this request.                                                                                                                                                                                                                                                                                             |
| side<mark style="color:red;">\*</mark>        | string | <p><strong>"spend"</strong> or <strong>"withdraw"</strong>.<br>Impacts <em>amount</em> field. When you want to withdraw the exact amount – specify the "withdraw" side. When you want to spend (exchange) an exact amount specify "exchange" </p>                                                                                                                                              |
| fee<mark style="color:red;">\*</mark>         | string | withdrawal fee                                                                                                                                                                                                                                                                                                                                                                                 |
| price<mark style="color:red;">\*</mark>       | string | actual price of the pairs                                                                                                                                                                                                                                                                                                                                                                      |
| localId                                       | string | if was specified error will be thrown if not unique, can be useful on your side to avoid the [double-spend](https://en.wikipedia.org/wiki/Double-spending) issue                                                                                                                                                                                                                               |
| meta                                          | string | metadata that you can define and catch it back later with notification                                                                                                                                                                                                                                                                                                                         |
| to<mark style="color:red;">\*</mark>          | string | <p>credit card number<br>(destination of withdrawal)</p>                                                                                                                                                                                                                                                                                                                                       |
| spendTicker<mark style="color:red;">\*</mark> | String | <p>Ticker you want to spend (exchange) from your balance.</p><p>Find values using <a data-mention href="/pages/f4pta1OrCzRaTuWvgkEi#list-all-supported-crypto-assets">/pages/f4pta1OrCzRaTuWvgkEi#list-all-supported-crypto-assets</a> or <a data-mention href="/pages/EiL49iurLQydZGUemYNu#list-all-supported-fiat-assets">/pages/EiL49iurLQydZGUemYNu#list-all-supported-fiat-assets</a></p> |
| exchangeFee<mark style="color:red;">\*</mark> | string | fee for exchange operation                                                                                                                                                                                                                                                                                                                                                                     |

{% tabs %}
{% tab title="200: OK Exchange + Withdrawal has been created successfully" %}
{% code overflow="wrap" %}

```javascript
{
    "id": "123e4567-e89b-12d3-a456-426614174000" //internal ID has been assigned to the transaction
}
```

{% endcode %}
{% 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://docs.0xpay.app/public-api/endpoints/exchange-+-withdrawal.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.
