# Book Ticker Stream

Pushes any update to the best bid or ask's price or quantity in real-time for a specified symbol.

## Update Speed

* Pushed on each block.

## Subscribe Request

* Subscribe Schema

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

* Subscribe Ack Schema

See [`WsBookTickerSubscriptionResult`](https://sodex.com/documentation/rest-v1/schema#wsbooktickersubscriptionresult) 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: WsBookTickerSubscriptionResult | 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": "bookTicker",
    "symbols": ["vBTC_vUSDC"]
  }
}
```

* Example: Subscribe Ack

```json
{
  "op": "subscribe",
  "result": {
    "channel": "bookTicker",
    "symbol": "vBTC_vUSDC"
  },
  "success": true,
  "connID": "0x8f0bb08be0c03d12e3cd021b665e9a8d",
  "time_in": 1672515782130,
  "time_out": 1672515782136
}
```

## Unsubscribe Request

* Unsubscribe Schema

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

* Unsubscribe Ack Schema

See [`WsBookTickerSubscriptionResult`](https://sodex.com/documentation/rest-v1/schema#wsbooktickersubscriptionresult) 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: WsBookTickerSubscriptionResult | 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": "bookTicker",
    "symbols": ["vBTC_vUSDC"]
  }
}
```

* Example: Unsubscribe Ack

```json
{
  "op": "unsubscribe",
  "result": {
    "channel": "bookTicker",
    "symbol": "vBTC_vUSDC"
  },
  "success": true,
  "connID": "0x8f0bb08be0c03d12e3cd021b665e9a8d",
  "time_in": 1672515782130,
  "time_out": 1672515782136
}
```

## Snapshot / Update Response

* Snapshot / Update Schema

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

```typescript
interface BookTickerResponse {
  channel: "bookTicker";
  type: "snapshot" | "update";
  data: Array<WsBookTickerData>;
}
```

* Example: Snapshot

```json
{
  "channel": "bookTicker",
  "type": "snapshot",
  "data": [
    {
      "E": 1766844967026,
      "s": "vBTC_vUSDC",
      "u": 2631,
      "a": "99380",
      "A": "0.94474",
      "b": "99165",
      "B": "0.94382"
    }
  ]
}
```

* Example: Update

```json
{
  "channel": "bookTicker",
  "type": "update",
  "data": [
    {
      "E": 1766844967026,
      "s": "vBTC_vUSDC",
      "u": 2631,
      "a": "99380",
      "A": "0.94474",
      "b": "99165",
      "B": "0.94382"
    }
  ]
}
```
