# Exchange Request

Effortlessly initiate currency conversions for a specific amount from one cryptocurrency to another in real-time, receiving your desired currency at the prevailing global market price. To explore the available conversion options, refer to the [exchange pairs](/legacy/api-reference/exchange-pairs.md) endpoint, which provides a comprehensive list of supported currency pairs for seamless transactions. Whether you're swapping Bitcoin for Tether or Tether for Litecoin, this feature ensures quick and accurate conversions at the current market rates.

<mark style="color:green;">`POST`</mark> `https://api.oxapay.com/exchange/request`

To use this endpoint, you need to make a POST request to the specified URL with the required parameters. The typical parameters for this request include:

#### Request Body

<table><thead><tr><th width="162">Name</th><th width="100">Type</th><th>Description</th></tr></thead><tbody><tr><td>key<mark style="color:red;">*</mark></td><td>string</td><td>Your general API key for authentication and authorization.</td></tr><tr><td>toCurrency<mark style="color:red;">*</mark></td><td>string</td><td>The <a href="/pages/J7efulCOZC0zGKzpVHol">currency</a> code of the cryptocurrency you want to convert to</td></tr><tr><td>fromCurrency<mark style="color:red;">*</mark></td><td>string</td><td>The <a href="/pages/J7efulCOZC0zGKzpVHol">currency</a> code of the cryptocurrency you want to convert from</td></tr><tr><td>amount<mark style="color:red;">*</mark></td><td>decimal</td><td>The amount of cryptocurrency to you want to exchange</td></tr></tbody></table>

{% tabs %}
{% tab title="200: OK After the payout request is made, the response will contain the following information:" %}

```json
{
  "result": integer, // The result code indicates the success or failure of the request.
  "message": string, // A message providing additional information about the result.
  "trackId": string, // The unique identifier for the payout request in the OxaPay payment gateway. 
  "status": string, // The current status of the payout (Processing, Sending, Complete, or Rejected).
  "amount": string, // The amount you want to exchange
  "fromCurrency": string, // The currency code of the cryptocurrency you want to convert from
  "toCurrency": string, // The currency code of the cryptocurrency you want to convert to
  "toAmount": string, // The amount you'll receive in your desired cryptocurrency.
  "rate": string, // The real-time exchange rate representing the number of units of `fromCurrency` equivalent to `toCurrency`.
  "date": string // exchange time
}
```

{% endtab %}
{% endtabs %}

Please ensure that you provide the necessary parameters accurately in the request to create a exchange request successfully.

Please note that a successful request will return a result code 100. In case of any issues or validation problems, refer to the corresponding [result codes](/legacy/api-reference/result-code-table.md) for further details.

### Example codes

{% tabs %}
{% tab title="cURL" %}

```bash
curl -X POST https://api.oxapay.com/exchange/request \
-d '{
  "key": "YOUR_GENERAL_API_KEY",
  "amount": 0.5,
  "fromCurrency": "BTC",
  "toCurrency": "USDT"
}'
```

{% endtab %}

{% tab title="PHP" %}

```php
<?php

$url = 'https://api.oxapay.com/exchange/request';

$data = array(
  'key' => 'YOUR_GENERAL_API_KEY',
  'amount": 0.5,
  'fromCurrency': 'BTC',
  'toCurrency': 'USDT'
);

$options = array(
    'http' => array(
        'header' => 'Content-Type: application/json',
        'method'  => 'POST',
        'content' => json_encode($data),
    ),
);

$context  = stream_context_create($options);
$response = file_get_contents($url, false, $context);
$result = json_decode($response);
var_dump($result);
?>
```

{% endtab %}

{% tab title="Node.js" %}

```javascript
const axios = require('axios');
const url = 'https://api.oxapay.com/exchange/request';
const data = {
  key: 'YOUR_GENERAL_API_KEY',
  amount: 0.5,
  fromCurrency: 'BTC',
  toCurrency: 'USDT'
};

axios.post(url, data)
  .then(response => {
    console.log(response.data);
  })
  .catch(error => {
    console.error(error.response.data);
  });
```

{% endtab %}

{% tab title="Python" %}

```python
import requests
import json

url = 'https://api.oxapay.com/exchange/request'
data = {
  'key': 'YOUR_GENERAL_API_KEY',
  'amount': 0.5,
  'fromCurrency': 'BTC',
  'toCurrency': 'USDT'
}
response = requests.post(url, data=json.dumps(data))
result = response.json()
print(result)
```

{% endtab %}
{% endtabs %}

Replace `YOUR_GENERAL_API_KEY` with your actual API key and adjust the parameters as needed for your specific use case.


---

# 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.oxapay.com/legacy/api-reference/exchange-request.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.
