> 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/client-api/subscription-to-account-details.md).

# Subscription to account details

This page describes mechanism of receiving account data via websocket

## Connection

In order to receive account data, the connection should be opened to `wss://sandbox-api.traderevolution.com/traderevolution/v1/stream/accounts`**.**&#x20;

{% hint style="warning" %}
Please note that the URL specified for connection is default, but it can be customized according to the customer's requirements.
{% endhint %}

There is a "Ping-Pong" mechanism for WebSocket connections. To maintain active WebSocket connections and detect client inactivity, the following message format is used:

```json
{"event": "PING", "t": 1731538318526}
{"event": "PONG", "t": 1731538318526}
```

## Subscribing to account data

The request body must contain the following parameters:

**Body**

| Name        | Type    | Description                                                                                              |
| ----------- | ------- | -------------------------------------------------------------------------------------------------------- |
| `event`     | string  | Should be always `subscribe` in this case.                                                               |
| `requestId` | integer | Request identifier generated by the client side. Will be used in the response.                           |
| `payload`   | object  | An object that contains information about the stream to which the subscription is made, see table below. |

**Payload object**

| Parameter   | Value                                                                                                                                                                                                                                                                                                                                                                                                                            |
| ----------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `accountId` | Optional parameter that defines the ID of the account for which the subscription will be performed. If this parameter is not specified, then you will be subscribed to the updates of all accounts.                                                                                                                                                                                                                              |
| `st*`       | <p>The subscription type is specified here. </p><p>The following values can be used here:</p><p><code>accountDetailsData</code> – this subscription provides information on account statistics: balances, account activity, margin, etc.</p><p><code>account</code> – this subscription provides information regarding changes in the account settings, e.g., changes in the account status, changes in the risk rules, etc.</p> |

**Request body example**

Copy

```json
{
	"event": "subscribe",
	"requestId": 123,
	"payload": {
		"accountId": 13466,
		"st": "account"
	}
}
```

### **Account details response structure**

An object with the following parameters will be returned in the response for the subscription to the account details data:

| Parameter   | Value                                                                            |
| ----------- | -------------------------------------------------------------------------------- |
| `d`         | Object with the account details data.                                            |
| `s`         | Subscription status indicator: `ok` or `error` in case the subscription fails.   |
| `errmsg`    | This parameter contains the text of the error which occurred when ***s=error***. |
| `st`        | Always returned as `accountDetailsData` here.                                    |
| `accountId` | Identifier of the account.                                                       |

The Account details array has the same sequence of parameters as in `accountStateResponse` model.

{% hint style="success" %}
You can find the full list of parameters by following the link to `stateResponse` model:

<https://guide.traderevolution.com/traderevolution-api/traderevolution-apis/client-rest-api/account-management#account-state>
{% endhint %}

**Response example**

```json
{
	"s": "ok"
	"st": "accountDetailsData"
        "d": {
		"accountDetailsData": [
			0
		]
	}
}
```

### Account response structure

An object with the following parameters will be returned in the response for the subscription to the account data:

| Parameter   | Value                                                                            |
| ----------- | -------------------------------------------------------------------------------- |
| `d`         | Object with account settings.                                                    |
| `s`         | Subscription status indicator: `ok` or `error` in case the subscription fails.   |
| `errmsg`    | This parameter contains the text of the error which occurred when ***s=error***. |
| `st`        | Always returned as `account` here.                                               |
| `accountId` | Identifier of the account.                                                       |

### Unsubscribing from account data

To stop receiving updates for account data via WebSocket, you must send an unsubscribe request that mirrors the subscription format, with `"event": "unsubscribe"`.

**Request body parameters**

| Name        | Type    | Description                                           |
| ----------- | ------- | ----------------------------------------------------- |
| `event`     | string  | Must always be `"unsubscribe"` in this case.          |
| `requestId` | integer | Client-side generated request identifier.             |
| `payload`   | object  | Contains details for unsubscription. See table below. |

**Payload object**

| Parameter   | Description                                                                                                    |
| ----------- | -------------------------------------------------------------------------------------------------------------- |
| `accountId` | Optional. If provided, the unsubscription applies only to that account.                                        |
| `st`        | Required. The type of account subscription to unsubscribe from. Valid values: `account`, `accountDetailsData`. |

**Request body example**:

```json
{
  "event": "unsubscribe",
  "requestId": 999,
  "payload": {
    "accountId": 13466,
    "st": "accountDetailsData"
  }
}
```

**Unsubscribing from all events**

To unsubscribe from all account-related subscriptions for a specific account, omit the `st` parameter and provide only the `accountId`.

**Example:**

```json
{
  "event": "unsubscribe",
  "requestId": 1000,
  "payload": {
    "accountId": 13466
  }
}
```

This will cancel all subscriptions (e.g., `account`, `accountDetailsData`) related to the specified account.

If **`accountId` is also omitted**, the unsubscription applies only to **subscriptions without specific account targeting**, as per user visibility.
