# Account Events Stream

User events that are not order updates or trades

* Liquidation - perps only

## Update Speed

* Pushed on each block.

## Subscribe Request

* Subscribe Schema

See [`WsUserEventSubscriptionParams`](https://sodex.com/documentation/rest-v1/schema#wsusereventsubscriptionparams) 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: WsUserEventSubscriptionParams;
}
```

* Subscribe Ack Schema

See [`WsUserEventSubscriptionResult`](https://sodex.com/documentation/rest-v1/schema#wsusereventsubscriptionresult) 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: WsUserEventSubscriptionResult | 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": "accountEvent",
    "user": "0xed3e79ef16a7890e6eaef2aa6373b6bec5d59d5c"
  }
}
```

* Example: Subscribe Ack

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

## Unsubscribe Request

* Unsubscribe Schema

See [`WsUserEventSubscriptionParams`](https://sodex.com/documentation/rest-v1/schema#wsusereventsubscriptionparams) 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: WsUserEventSubscriptionParams;
}
```

* Unsubscribe Ack Schema

See [`WsUserEventSubscriptionResult`](https://sodex.com/documentation/rest-v1/schema#wsusereventsubscriptionresult) 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: WsUserEventSubscriptionResult | 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": "accountEvent",
    "user": "0xed3e79ef16a7890e6eaef2aa6373b6bec5d59d5c"
  }
}
```

* Example: Unsubscribe Ack

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

## Update Response

* Update Schema

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

```typescript
interface AccountEventResponse {
  channel: "accountEvent";
  type: "update";
  data: WsUserEvent;
}
```

* Example: Update

```json
{
  "channel": "accountEvent",
  "type": "update",
  "data": {
    "type": "liquidation",
    "lid": 1000,
    "aid": 1002,
    "av": "123",
    "mm": "CROSS",
    "B": [
      {
        "i": 0,
        "a": "vUSDC",
        "wb": "10"
      }
    ],
    "P": [
      {
        "s": "BTC-USD",
        "ps": "BOTH",
        "sz": "-0.00001",
        "mp": "200000",
        "lp": "100000"
      }
    ]
  }
}
```
