# Exchange Rate

The endpoint allows users to obtain real-time exchange rates for cryptocurrency pairs supported by OxaPay. This feature is particularly useful for applications that require up-to-date cryptocurrency prices.

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

#### Request Body

<table><thead><tr><th width="170">Name</th><th width="100">Type</th><th>Description</th></tr></thead><tbody><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>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></tbody></table>

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

```json
{
  "result": integer, // The result code indicates the success or failure of the request.
  "message": string, // A message providing additional information about the result.
  "rate": string // The real-time exchange rate representing the number of units of `fromCurrency` equivalent to `toCurrency`.
}
```

{% endtab %}
{% endtabs %}

### Example codes

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

```bash
curl -X POST https://api.oxapay.com/exchange/rate \
     -d '{
          "fromCurrency": "USDT",
          "toCurrency": "TRX"
      }'
```

{% endtab %}

{% tab title="PHP" %}

```php
<?php

$url = "https://api.oxapay.com/exchange/rate";

$data = array(
    "fromCurrency" => "USDT",
    "toCurrency" => "TRX"
);

$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/rate';
const data = JSON.stringify({
  fromCurrency: 'USDT',
  toCurrency: 'TRX'
});

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

{% endtab %}

{% tab title="Python" %}

```python
import requests
import json

url = 'https://api.oxapay.com/exchange/rate'
data = {
    'fromCurrency': 'USDT',
    'toCurrency': 'TRX'
}
response = requests.post(url, data=json.dumps(data))
result = response.json()
print(result)
```

{% endtab %}
{% endtabs %}

### Usage

By providing the \`fromCurrency\` and \`toCurrency\` parameters, you can retrieve the exchange rate between the specified cryptocurrencies. For example, if you set \`fromCurrency\` to "BTC" and \`toCurrency\` to "USDT," the response will provide the real-time exchange rate for converting Bitcoin (BTC) to Tether (USDT).

Please note that the exchange rate provided in the response may fluctuate over time due to the volatile nature of cryptocurrency markets.

<br>


---

# 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-rate.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.
