# Market Trades Stream

The Trade Streams push raw trade information; each trade has a unique buyer and seller.

## Update Speed

* Pushed on each block.

## Subscribe Request

* Subscribe Schema

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

* Subscribe Ack Schema

See [`WsTradeSubscriptionResult`](https://sodex.com/documentation/rest-v1/schema#wstradesubscriptionresult) 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: WsTradeSubscriptionResult | 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": "trade",
    "symbols": ["BTC-USD"]
  }
}
```

* Example: Subscribe Ack

```json
{
  "op": "subscribe",
  "result": {
    "channel": "trade",
    "symbol": "BTC-USD"
  },
  "success": true,
  "connID": "0xb0922dfe2b14dadb1195ea4db2b45508",
  "time_in": 1672515782130,
  "time_out": 1672515782136
}
```

## Unsubscribe Request

* Unsubscribe Schema

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

* Unsubscribe Ack Schema

See [`WsTradeSubscriptionResult`](https://sodex.com/documentation/rest-v1/schema#wstradesubscriptionresult) 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: WsTradeSubscriptionResult | 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": "trade",
    "symbols": ["BTC-USD"]
  }
}
```

* Example: Unsubscribe Ack

```json
{
  "op": "unsubscribe",
  "result": {
    "channel": "trade",
    "symbol": "BTC-USD"
  },
  "success": true,
  "connID": "0xb0922dfe2b14dadb1195ea4db2b45508",
  "time_in": 1672515782130,
  "time_out": 1672515782136
}
```

## Update Response

* Update Schema

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

```typescript
interface MarketTradeResponse {
  channel: "trade";
  type: "update";
  data: Array<WsTrade>;
}
```

* Example: Update

```json
{
  "channel": "trade",
  "type": "update",
  "data": [
    {
      "E": 1766846445234,
      "T": 1766846558207,
      "t": 4352,
      "s": "vBTC_vUSDC",
      "S": "BUY",
      "p": "100732",
      "q": "0.0007",
      "bi": 247817583,
      "si": 1001
    },
    {
      "E": 1766846445234,
      "T": 1766846558207,
      "t": 4301,
      "s": "vETH_vUSDC",
      "S": "BUY",
      "p": "3483.5",
      "q": "0.0128",
      "bi": 4990429548,
      "si": 1001
    }
  ]
}
```
