# Account Updates Stream

Pushed when account balances or positions (perps only) are updated.

## Update Speed

* Pushed on each block.

## Subscribe Request

* Subscribe Schema

See [`WsAccountUpdateSubscriptionParams`](https://sodex.com/documentation/rest-v1/schema#wsaccountupdatesubscriptionparams) in [Schema](https://sodex.com/documentation/api/rest-v1/schema).

```typescript
interface SubscribeRequest {
  op: "subscribe";
  id: number | null; // Optional client originated request identifier sent as acknowledgment in the response.
  params: WsAccountUpdateSubscriptionParams;
}
```

* Subscribe Ack Schema

See [`WsAccountUpdateSubscriptionResult`](https://sodex.com/documentation/rest-v1/schema#wsaccountupdatesubscriptionresult) in [Schema](https://sodex.com/documentation/api/rest-v1/schema).

```typescript
interface SubscriptionResult {
  op: "subscribe";
  id: number | null; // Optional client originated request identifier sent as acknowledgment in the response.
  result: WsAccountUpdateSubscriptionResult | null;
  success: boolean; // Indicates if the request was successfully processed by the engine.
  connID: string;
  error: string | null; // Condition: If success is false. Error message.
  time_in: number; // The timestamp when the subscription was received on the wire, just prior to parsing data, in milliseconds.
  time_out: number; // The timestamp when the acknowledgement was sent on the wire, just prior to transmitting data, in milliseconds.
}
```

* Example: Subscribe

```json
{
  "op": "subscribe",
  "params": {
    "channel": "accountUpdate",
    "user": "0xed3e79ef16a7890e6eaef2aa6373b6bec5d59d5c"
  }
}
```

* Example: Subscribe Ack

```json
{
  "op": "subscribe",
  "result": {
    "channel": "accountUpdate",
    "user": "0xed3e79ef16a7890e6eaef2aa6373b6bec5d59d5c",
    "accountID": 1001
  },
  "success": true,
  "connID": "0xb0922dfe2b14dadb1195ea4db2b45508",
  "time_in": 1672515782130,
  "time_out": 1672515782136
}
```

## Unsubscribe Request

* Unsubscribe Schema

See [`WsAccountUpdateSubscriptionParams`](https://sodex.com/documentation/rest-v1/schema#wsaccountupdatesubscriptionparams) in [Schema](https://sodex.com/documentation/api/rest-v1/schema).

```typescript
interface UnsubscribeRequest {
  op: "unsubscribe";
  id: number | null; // Optional client originated request identifier sent as acknowledgment in the response.
  params: WsAccountUpdateSubscriptionParams;
}
```

* Unsubscribe Ack Schema

See [`WsAccountUpdateSubscriptionResult`](https://sodex.com/documentation/rest-v1/schema#wsaccountupdatesubscriptionresult) in [Schema](https://sodex.com/documentation/api/rest-v1/schema).

```typescript
interface UnsubscriptionResult {
  op: "unsubscribe";
  id: number | null; // Optional client originated request identifier sent as acknowledgment in the response.
  result: WsAccountUpdateSubscriptionResult | null;
  success: boolean; // Indicates if the request was successfully processed by the engine.
  connID: string;
  error: string | null; // Condition: If success is false. Error message.
  time_in: number; // The timestamp when the subscription was received on the wire, just prior to parsing data, in milliseconds.
  time_out: number; // The timestamp when the acknowledgement was sent on the wire, just prior to transmitting data, in milliseconds.
}
```

* Example: Unsubscribe

```json
{
  "op": "unsubscribe",
  "params": {
    "channel": "accountUpdate",
    "user": "0xed3e79ef16a7890e6eaef2aa6373b6bec5d59d5c"
  }
}
```

* Example: Unsubscribe Ack

```json
{
  "op": "unsubscribe",
  "result": {
    "channel": "accountUpdate",
    "user": "0xed3e79ef16a7890e6eaef2aa6373b6bec5d59d5c",
    "accountID": 1001
  },
  "success": true,
  "connID": "0xb0922dfe2b14dadb1195ea4db2b45508",
  "time_in": 1672515782130,
  "time_out": 1672515782136
}
```

## Update Response

* Update Schema

See [`WsSpotAccountUpdate`](https://sodex.com/documentation/rest-v1/schema#wsspotaccountupdate), [`WsPerpsAccountUpdate`](https://sodex.com/documentation/rest-v1/schema#wsperpsaccountupdate) in [Schema](https://sodex.com/documentation/api/rest-v1/schema).

```typescript
interface AccountUpdateResponse {
  channel: "accountUpdate";
  type: "update";
  data: WsSpotAccountUpdate | WsPerpsAccountUpdate;
}
```

* Example: Update

```json
{
  "channel": "accountUpdate",
  "type": "update",
  "data": {
    "E": 1766847039189,
    "h": 2211,
    "B": [
      { "i": 1, "a": "vBTC", "t": "10113.00266312", "l": "4.57789" },
      {
        "i": 0,
        "a": "vUSDC",
        "t": "999998045.21473685",
        "l": "1948375.89155815"
      },
      { "i": 2, "a": "vETH", "t": "287322.7167728536949776", "l": "115.0146" },
      {
        "i": 3,
        "a": "vPEPE",
        "t": "163666213677145.6235679214402619",
        "l": "90965473761"
      },
      {
        "i": 4,
        "a": "WSOSO",
        "t": "1355197181.1898631250846998",
        "l": "729242.63"
      }
    ]
  }
}
```
