> For the complete documentation index, see [llms.txt](https://guide.traderevolution.com/traderevolution-api/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://guide.traderevolution.com/traderevolution-api/traderevolution-apis/backoffice-api/sorting-algorithms.md).

# Sorting Algorithms

Sorting algorithms help you quickly identify the most active and relevant trading instruments by automatically organizing them based on price movement, volume, or user trading behavior. These lists are generated using live or historical market data via the BackOffice API.\
Available types:

* High / Low – shows instruments that have reached or exceeded the current daily high or low price;
* Gainers / Losers – displays two separate lists: instruments with the highest positive percentage change ("Gainers") and those with the largest negative change ("Losers") based on the "Change %" parameter;
* Consensus – highlights instruments with the most Buy and most Sell activity among users, helping to identify the "hottest" (most bought) and "coldest" (most sold) instruments at the moment;
* Top Volume – lists instruments with the highest total traded volume for the current day;
* Historical Gainers / Losers – shows the top gainers and losers from previous trading sessions, based on historical performance;
* Most Traded – ranks instruments by the number of executed trades, regardless of trade volume.

## Get available algorithms

<mark style="color:blue;">`GET`</mark>`/algorithms`

This API method is used to get a list of all algorithms available on this server. Algorithms can be filtered by specifying the appropriate filtration method in the request query. All available values are listed in the table below.&#x20;

**Query**

<table><thead><tr><th>Name</th><th width="208">Type</th><th>Description</th></tr></thead><tbody><tr><td><code>name</code></td><td>string</td><td>Name of the algorithm</td></tr><tr><td><code>status</code></td><td>string</td><td>Algorithm status. Several values can be specified separated by commas. Available values:<br>0 - Active/Running<br>1 - Stopped<br>2 - Inactive</td></tr><tr><td><code>type</code></td><td>string</td><td><p>Type of the algorythm, valid values: </p><p><em>High / Low - 0</em> </p><p><em>Gainers / Losers - 1</em> </p><p><em>Consensus - 2</em> </p><p><em>Top volume - 3</em> </p><p><em>Historical gainer loser tops - 4</em> </p><p><em>Most traded - 5</em></p></td></tr></tbody></table>

**CURL (example request for Inactive = 2 algorithm type)**

{% code overflow="wrap" %}

```json
curl -X GET "http://sandbox.traderevolution.com:8443/proftrading/rest/algorithms?status=2" -H "accept: application/json" -H "Authorization: Bearer eyIxMDQ3OTQ5Mjg0IjoxMDQ3OTQ5Mjg0LCItNjA2MTY0Mjg2IjotNjA2MTY0Mjg2LCI2MTI5NjI0NzciOjYxMjk2MjQ3NywiOTQ2NDkzNzc5Ijo5NDY0OTM3N...mM4BGDOhYLIVO5qbFG01RrG8_h3sSmTb8pZjR_dzkZiR1eAdxZLsY4AgAA.VC6bFF0oHmns38wFUHkTAb6H5mz77Gj6LG97JExcr-U"
```

{% endcode %}

**Response**

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

```json
[
  {
    "id": 1420,
    "algorithmType": 3,
    "name": "New top volume",
    "status": 2
  }
]
```

{% endtab %}
{% endtabs %}

The filtered response contains one algorithm with `status=2` (Inactive). The response contains the list of algorithms with details such as *id*, *algorithmType*, *name*, and *status*. All standard errors can be returned for this method as well.&#x20;

{% hint style="success" %}
You can try this method by following the link:

<https://sandbox.traderevolution.com:8443/proftrading/rest/swagger-ui.html#/Algorithms/getAlgorithmsUsingGET>
{% endhint %}

## Create algorithm

<mark style="color:green;">`POST`</mark> `/algorithms`

This method is used to create a new algorithm on the server. Various parameters can be configured here, which will be applied to the newly created algorithm.

**Body**

| Name            | Type    | Description                                                                                                                                                                                                                          |
| --------------- | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `name`          | string  | Name of the algorithm                                                                                                                                                                                                                |
| `algorithmType` | integer | <p>Algorithm type:<br><em>High / Low - 0</em> </p><p><em>Gainers / Losers - 1</em> </p><p><em>Consensus - 2</em> </p><p><em>Top volume - 3</em> </p><p><em>Historical gainer loser tops - 4</em> </p><p><em>Most traded - 5</em></p> |
| `comment`       | string  | Text definition of the algorithm                                                                                                                                                                                                     |
| `nodes`         | integer | The choice of the algorithmic node on which the algorithm should work                                                                                                                                                                |
| `paramsList`    | string  | An array of algorithm parameters. Each element of the array is an object that characterizes an algorithm parameter. Each object is described by the name of the algorithm and the value of the parameter                             |

**CURL**

{% code overflow="wrap" %}

```json
curl -X POST "http://sandbox.traderevolution.com:8443/proftrading/rest/algorithms" -H "accept: application/json" -H "Authorization: Bearer eyI1Nzc3MjIzMDMiOjU3NzcyM…AA.N98cOKnuSbV4qVVMwbg09invQLP_hhOLkUyxw8FrKCY" -H "Content-Type: application/json" -d "{ \"algorithmType\": 2, \"comment\": \"string\", \"name\": \"new algorithm\", \"nodes\": [ 12, 34, 56 ], \"paramsList\": { \"additionalProp1\": \"string\", \"additionalProp2\": \"string\", \"additionalProp3\": \"string\" }}"
```

{% endcode %}

The full list of *additionalProps* for each algorithm type can be found by using the <mark style="color:blue;">`GET`</mark>`/algorithms/types/{typeId}` method.&#x20;

**Response**

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

```json
{
  "id": 529356,
  "name": "new algorithm"
}
```

{% endtab %}
{% endtabs %}

In the response, you will receive the ID of the newly created algorithm along with its name.

{% hint style="success" %}
You can try this method of BO REST API here:\
<https://sandbox.traderevolution.com:8443/proftrading/rest/swagger-ui.html#/Algorithms/createAlgorithmUsingPOST>
{% endhint %}

## Patch algorithm

<mark style="color:green;">`PATCH`</mark>`/algorithms/{algorithmId}`

This method is used to update an algorithm on the server. It requires the ID of the algorithm in the request path and parameters for the algorithm update in the body (same parameters as for `POST`).

**Path/Body**

| Name            | Type         | Description                                                                                                                                                                                                                          |
| --------------- | ------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `id`            | integer/path | ID of the algorithm to be modified                                                                                                                                                                                                   |
| `name`          | string/body  | Name of the algorithm                                                                                                                                                                                                                |
| `algorithmType` | integer/body | <p>Algorithm type:<br><em>High / Low - 0</em> </p><p><em>Gainers / Losers - 1</em> </p><p><em>Consensus - 2</em> </p><p><em>Top volume - 3</em> </p><p><em>Historical gainer loser tops - 4</em> </p><p><em>Most traded - 5</em></p> |
| `comment`       | string/body  | Text definition of the algorithm                                                                                                                                                                                                     |
| `nodes`         | integer/body | The choice of the algorithmic node on which the algorithm should work                                                                                                                                                                |
| `paramsList`    | string/body  | An array of algorithm parameters. Each element of the array is an object that characterizes an algorithm parameter. Each object is described by the name of the algorithm and the value of the parameter                             |

**CURL**

{% code overflow="wrap" %}

```json
curl -X PATCH "http://sandbox.traderevolution.com:8443/proftrading/rest/algorithms/264943" -H "accept: application/json" -H "Authorization: Bearer eyItMTY5MTQ4N…d7_k7WUblGV_deQ5ydc" -H "Content-Type: application/json" -d "{ \"algorithmType\": 0, \"comment\": \"Updated algorithm comment\", \"name\": \"Updated algorithm name\", \"nodes\": [ 12, 34, 56 ], \"paramsList\": { \"additionalProp1\": \"updatedValue1\", \"additionalProp2\": \"updatedValue2\", \"additionalProp3\": \"updatedValue3\" }}"
```

{% endcode %}

The full list of *additionalProps* for each algorithm type can be found by using the <mark style="color:blue;">`GET`</mark>`/algorithms/types/{typeId}` method.&#x20;

**Response**

In the response, the 200 OK status will be received and the algorithm parameters will be updated on the server.

{% hint style="success" %}
You can play with this method of BO REST API here:

<https://sandbox.traderevolution.com:8443/proftrading/rest/swagger-ui.html#/Algorithms/editAlgorithmUsingPATCH>
{% endhint %}

## Delete algorithm

<mark style="color:red;">`DELETE`</mark>`/algorithms/{id}`

This method is used to remove the algorithm from the server. It requires only one *path* parameter - the ID of the algorithm that needs to be removed.

**Path**

| Name | Type    | Description                       |
| ---- | ------- | --------------------------------- |
| `id` | integer | ID of the algorithm to be deleted |

**CURL**

{% code overflow="wrap" %}

```json
curl -X DELETE "http://sandbox.traderevolution.com:8443/proftrading/rest/algorithms/120" -H "accept: application/json" -H "Authorization: Bearer eyItMTg4MDEzOTE2Ijo…w4OEaWbMiY"
```

{% endcode %}

**Response**

In the response, you will receive the `200 OK` status whisc indicates the successful deletion of the algorithm.

{% hint style="success" %}
You can try this method of BO REST API here:

<https://sandbox.traderevolution.com:8443/proftrading/rest/swagger-ui.html#/Algorithms/deleteAlgorithmUsingDELETE>
{% endhint %}
