> 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/trading-accounts.md).

# Trading accounts

This section describes adding a trading account to the created user. Please note that trading is unavailable without at least one account assigned to the user by his ID. The article shows the process of adding a trading account. Please note that you can use account presets here, find more info on managing these presets in the corresponding [article](https://guide.traderevolution.com/traderevolution-api/traderevolution-apis/backoffice-rest-api/account-presets).&#x20;

{% hint style="success" %}
A full list of parameters available for account creation can be found here:

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

The account is created with a server currency (Configuration > Settings > General) and is in an Active state by default (ready for trade after the deposit). The account ID will be used in your following requests, i.e. to perform deposit or other account operations.

## Add trading account

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

This method is used for the creation of a trading account and assigning it to a certain user by [its ID](/traderevolution-api/traderevolution-apis/backoffice-api/user-management.md#find-user-by-login-e-mail-etc).&#x20;

**Body**

| Name          | Type    | Description                                                    |
| ------------- | ------- | -------------------------------------------------------------- |
| `accountName` | string  | Name of the new account                                        |
| `userId`      | integer | ID of the user, to which this trading account will be assigned |

**Request**

```json
{
  "accountName": "1234acc",
  "userId": 146695
}
```

**CURL**

{% code overflow="wrap" %}

```json
curl -X POST "http://sandbox.traderevolution.com:8443/proftrading/rest/accounts" -H "accept: application/json" -H "Authorization: Bearer eyItMjI2OTkxMTE4IjotMjI2OTkxMTE...3QypO3xI7LJkLEiuMnd4_epgBqF3z_TRGULkAIAAA.4P7Xssd4FUvIWg2F3Evfd7YGInHwQ-rGfBsBOWbJpPo" -H "Content-Type: application/json" -d "{ \"accountName\": \"1234acc\", \"userId\": 146695}"
```

{% endcode %}

**Response**

{% tabs %}
{% tab title="200 (OK)" %}

```json
{
  "id": 680173,
  "name": "1234acc"
}
```

{% endtab %}
{% endtabs %}

Please note that you can create a trading account and assign it to the user using two parameters only: `accountName` and `userId`. In this case, standard settings will be applied to the newly created account:

* currency = server currency (configuration > settings > general)
* type: 0 = single account
* status: 0 = active
* mode: 1 = Live

## Find trading accounts by user ID

<mark style="color:blue;">`GET`</mark>`/users/{userId}/accounts`

This method allows to find all trading accounts of the user by his ID.&#x20;

**Path**

| Name     | Type    | Description                                                            |
| -------- | ------- | ---------------------------------------------------------------------- |
| `userId` | integer | ID of the user whose trading accounts will be returned in the response |

**CURL**

{% code overflow="wrap" %}

```json
curl -X GET "https://sandbox.traderevolution.com:8443/proftrading/rest/users/30234/accounts" -H  "accept: application/json" -H  "Authorization: Bearer eyIxMzUz…zNyuef4"
```

{% endcode %}

**Response**

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

```json
[
  {
    "id": 30234,
    "name": "demo"
  }
]
```

{% endtab %}
{% endtabs %}

In response, you will get the ID of all accounts linked to the specified user.&#x20;

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

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

## Changing account status

<mark style="color:yellow;">`PATCH`</mark>`/accounts/{account ID}`

This section describes the process of changing the account status (i.e. only one parameter will be updated) with a PATCH method. Please note that you can change any account setting using this method.&#x20;

{% hint style="success" %}
A full list of parameters available for patching the trading account can be found here:

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

**CURL**

{% code overflow="wrap" %}

```json
curl -X PATCH "https://sandbox.traderevolution.com:8443/proftrading/rest/accounts/679776" -H "accept: application/json" -H "Authorization: Bearer eyItMTQzMzYxMjY3OCI6LTE0MzM2MTI2NzgsIjEyN...yLRrWfZTpA_U2-PoGHyEg5cwBAAA.KRfOCGRqPh-Nzxnzm-7rKDou92_7Lc5kqB6PEZGMo0k" -H "Content-Type: application/json" -d "{ \"status\": 1}"
```

{% endcode %}

As you can see, the request contains the account ID and a new status value **"1"**- which means the account will be closed. Available values here are *0 - Active, 1 - Closed, 2 - Suspended, 3 - Trading is disabled by risk rules, and 5 - Liquidation only (the account can only close positions and cancel orders).*&#x20;

**Response**

You will receive the `204 (No content)` code in the response, meaning the account has been patched successfully.

## Current account status

<mark style="color:blue;">`GET`</mark>`/accounts/{accountId}`

This method returns all settings of the account by its ID. This section describes the `status` field.&#x20;

{% hint style="success" %}
You can find all response fields by following the link:

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

**Path**

| Name        | Type    | Description                                       |
| ----------- | ------- | ------------------------------------------------- |
| `accountId` | integer | ID of the account whose settings will be returned |

**CURL**

{% code overflow="wrap" %}

```json
curl -X GET "https://sandbox.traderevolution.com:8443/proftrading/rest/accounts/679776" -H "accept: application/json" -H "Authorization: Bearer eyItMTQzMzYxMjY3OCI6LTE0MzM2MTI2NzgsIjEyNzkwNjQ1OTciOjEyNzkwNjQ1OTcsIjEzMzE5MDE0MTUiOjEzMzE5MDE0MTUsIjU4MzY0Njk4...7Lc5kqB6PEZGMo0k"
```

{% endcode %}

**Response example**

{% tabs %}
{% tab title="200" %}
{% code overflow="wrap" %}

```json
{
  "accountName": "account1",
  "accountAlias": "",
  "userId": 146695,
  "status": 0,
  "mode": 1,
  "description": "",
  "type": 0,
  "rules": [
    {
      "ruleName": "FUNCTION_EXT_RISK",
      "ruleValue": "0",
      "restriction": 0,
      "isOverridden": false
    },
    {
      "ruleName": "ALLOW_SHARIA_SWAP",
      "ruleValue": "0",
      "restriction": 0,
      "isOverridden": false
    },
    {
      "ruleName": "VALUE_MARGINCALL",
      "ruleValue": "100",
      "restriction": 0,
      "isOverridden": false
    },
    {
      "ruleName": "VALUE_INSTRUMENT_TYPE_LIMIT",
      "ruleValue": "{\"limits\":[]}",
      "restriction": 0,
      "isOverridden": false
    }
  ],
  "currencyId": 4803,
  "externalTradingProperties": [],
  "smaEquity": -1,
  "omnibusId": -1,
  "waivedMargin": -1,
  "calculatedDrawdown": 0,
  "presetId": -1,
  "preferredInstrumentType": -100
}
```

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

You should find the `status` field, it contains the current status of the account. Available values here are *0 - ACTIVE, 1 - CLOSED, 2 - SUSPENDED, 3 - TRADE\_OFF (trading is disabled), and 5 - LIQUIDATION\_ONLY (account can only close positions and cancel orders).* As you can see from the example, we have an *active* account `"accountName": "account1` with `"status": 0`.&#x20;

## Delete trading account by ID

<mark style="color:red;">`DELETE`</mark>`/accounts/{accountId}`

This method is used for removing a trading account from the server (it will be unassigned from the user-owner as well).&#x20;

{% hint style="danger" %}
Please note that this operation will remove all trading activity of this account! Be careful and avoid accidental usage of this method. &#x20;
{% endhint %}

**Path**

| Name        | Type    | Description                                     |
| ----------- | ------- | ----------------------------------------------- |
| `accountId` | integer | ID of the account to be removed from the server |

**CURL**

{% code overflow="wrap" %}

```json
curl -X DELETE "https://sandbox.traderevolution.com:8443/proftrading/rest/accounts/679775" -H "accept: application/json" -H "Authorization: Bearer eyI4NDU4NjE4MjIiOjg0NTg2MTgyMiwiMTU0NDE2OTgwNy...jdJO8-fb28C3Ip_j4BAqeYFp8AgAA.ZpJ-ojIbNebBsbomi6ZdiKkms4MZob0ohjPqviYNjHs"
```

{% endcode %}

You will receive the `204 (No content)` code in the response, meaning the account has been deleted successfully.

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

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

## Get account details

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

This request allows receiving the details for the required account. You can filter results by Account ID, request info by User group ID (for all users from the required group), or by User ID (data for all his accounts). The appropriate filtration should be specified in the request query.&#x20;

**Query**

| Name          | Type   | Description                                                   |
| ------------- | ------ | ------------------------------------------------------------- |
| `accountId`   | string | Identifier of the account for which the data is retrieved.    |
| `userGroupId` | string | Identifier of the user group for which the data is retrieved. |
| `userId`      | string | Identifier of the user for which the data is retrieved.       |

**CURL (example for account 146696)**

{% code overflow="wrap" %}

```json
curl -X GET "http://sandbox.traderevolution.com:8443/proftrading/rest/accountDetails?accountId=146696" -H "accept: application/json" -H "Authorization: Bearer eyIyMDgzMDU3ODk3IjoyMDgzMDU3ODk3LCItMTY3MDkxMDQ2NSI6LTE2NzA5MTA0NjUsIi0xODczMjI3OTE0IjotMTg3MzIyNzkxNCwiMTI4Mjk3NTQ2NyI...shGleFv3w0LmlRtCLA8XOqvxAzGmNy8_H-_N-Q2vj9A5qmtxb2AQAA.EzgtvR64bIpPPiXUaSESsHjXP4jKWlWuVAXw5R-8GbQ"
```

{% endcode %}

**Response**

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

```json
[
  {
    "accountId": 146696,
    "userId": 146695,
    "userGroupId": 570789,
    "trailingDrawdownLevel": -1,
    "eodTrailingDrawdownLevel": -1,
    "availableCash": 9320.4800922,
    "totalPositionsValue": 2206.034292,
    "leverageUsageWarn": 0,
    "assetId": 1,
    "balance": 10554.1607152,
    "projectedBalance": 11526.5143842,
    "balanceWithRisks": 10543.3143842,
    "creditValue": 0,
    "availableFunds": 10543.3143842,
    "blockedBalance": 211,
    "cashBalance": 10554.1607152,
    "unsettledCash": 983.2,
    "withdrawalAvailable": 9559.9143842,
    "interestRate": 0,
    "stockValue": 0,
    "optionValue": 0,
    "stocksLiquidity": 0,
    "initialMargin": 0,
    "initialMarginRate": 0,
    "maintenanceMarginRate": 0,
    "marginAvailable": 10543.3143842,
    "maintenanceMargin": 0,
    "blockedForStocks": 0,
    "stocksOrdersMargin": 0,
    "optionPremiumReq": 0,
    "openGrossPnL": -10.846331,
    "openNetPnL": -17.986331,
    "todaysGross": -971.8690764,
    "todaysNet": -4121.9990764,
    "todaysFees": 3150.13,
    "todaysTrades": 42,
    "todaysRebates": 0,
    "marginMarketValue": 0,
    "marginTradedBalance": 11537.3607152,
    "shortTradedBalance": 0,
    "marginEquity": 11537.3607152,
    "smaEquity": -1,
    "collateral": 0,
    "waivedMargin": -1,
    "warningMargin": 0,
    "warningMarginRate": 0,
    "marginBeforeWarning": 10543.3143842,
    "unusedSettledCashForStocks": 0,
    "unusedSettledCollateral": 0,
    "blockedForFixedIncome": 0,
    "fixedIncomeOrdersReq": 0
  }
]
```

{% endtab %}
{% endtabs %}

As you can see, the response contains the account/user ID and an object with all his indicators at the moment. The name of each parameter speaks for itself, but you can find a full description of each of them by following [this link](https://guide.traderevolution.com/project/desktop-application-for-windows/windows/account-information/accounts).&#x20;

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

<https://sandbox.traderevolution.com:8443/proftrading/rest/swagger-ui.html#/Accounts/getAccountDetailsUsingGET>&#x20;
{% endhint %}
