# Exchange History

Use this endpoint to retrieve a list of exchange transactions for a specific business. The list can be filtered by various criteria, such as time range, currency, type (autoConvert or manualSwap or swapByApi), and more. Pagination is also available to fetch the results in smaller sets.

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

#### 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>orderBy</td><td>string</td><td>Display the list in ascending or descending order. Possible values: 'asc', 'desc' [default 'desc'].</td></tr><tr><td>sortBy</td><td>string</td><td>Sort the received list by a parameter. Set to 'create_date' by default. Possible values: 'create_date', 'pay_date', 'amount' [default 'create_date'].</td></tr><tr><td>page</td><td>integer</td><td>The page number of the results you want to retrieve. Possible values: from 1 to the total number of pages - default 1.</td></tr><tr><td>size</td><td>integer</td><td>Number of records to be displayed on one page. Possible values: from 1 to 200 - default 10.</td></tr><tr><td>type</td><td>string</td><td>Filter exchanges based on type (autoConvert or manualSwap or swapByApi).</td></tr><tr><td>toCurrency</td><td>string</td><td>Specify the <a href="supported-currencies">currency symbol</a> for filtering exchanges in a specific toCurrency.</td></tr><tr><td>fromCurrency</td><td>string</td><td>Specify the <a href="supported-currencies">currency symbol</a> for filtering exchanges in a specific fromCurrency.</td></tr><tr><td>toDate</td><td>string</td><td>The start of the date window to query for exchanges in unix format</td></tr><tr><td>fromDate</td><td>string</td><td>The start of the date window to query for exchanges in unix format</td></tr><tr><td>trackId</td><td>integer</td><td>Filter spesific exchange by it`s trackId</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.
  "data": [
    {
      "trackId": string, // The uniqe id for the 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
      "fromAmount": string, // Amount you want to exchange
      "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`.
      "type": string, // The type of the exchange (e.g., \"autoConvert\" or \"manualSwap\" or \"swapByApi\").
      "date": string // The timestamp of the exchange transaction in Unix time format.
    }
  ],
  "meta": {
    "size": integer, // The number of exchange transactions returned in the current page.
    "page": integer, // The current page number of the result set.
    "pages": integer, // The total number of pages available based on the number of records and page size.
    "total": integer // The total number of exchange transactions available for the specified criteria.
  }
}
```

{% endtab %}
{% endtabs %}

Please note that this response sample includes a list of exchange transactions with their respective details and a metadata section providing information about the total number of records and pages available.

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](https://docs.oxapay.com/legacy/api-reference/result-code-table) for further details.

### Example codes

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

```bash
curl -X POST https://api.oxapay.com/exchange/list \
  -d '{
    "key": "YOUR_GENERAL_API_KEY",
    "fromDate": 1690848000,
    "toDate": 1691625600,
    "size": 20,
    "page": 0
  }'
```

{% endtab %}

{% tab title="PHP" %}

```php
<?php

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

$data = array(
    'key' => 'YOUR_GENERAL_API_KEY',
    'fromDate' => 1690848000,
    'toDate' => 1691625600,
    'size' => 20,
    'page' => 0
);

$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/list';
const data = JSON.stringify({
    key: 'YOUR_GENERAL_API_KEY',
    fromDate: 1690848000,
    toDate: 1691625600,
    size: 20,
    page: 0
});

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

{% endtab %}

{% tab title="Python" %}

<pre class="language-python"><code class="lang-python">import requests
import json

url = 'https://api.oxapay.com/exchange/list'
data = {
  'key': 'YOUR_GENERAL_API_KEY',
  'fromDate': 1690848000,
<strong>  'toDate': 1691625600,
</strong><strong>  'size': 20,
</strong>  'page': 0
}
response = requests.post(url, data=json.dumps(data))
result = response.json()
print(result)
</code></pre>

{% endtab %}
{% endtabs %}

Please remember to replace `YOUR_GENERAL_API_KEY` with your actual general API key and adjust the parameters as needed for your specific use case.
