> For the complete documentation index, see [llms.txt](https://sodex.com/documentation/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://sodex.com/documentation/trading-api/websocket-v1/coin-price.md).

# Coin Price Stream

Coin price and margin ratio for selected coins pushed on update. This stream is available for perps only.

## Update Speed

* Pushed on each block that is at least 1 second since the last push when price or margin ratio changes.

## Subscribe Request

* Subscribe Schema

See [`WsCoinPriceSubscriptionParams`](/documentation/trading-api/rest-v1/schema.md#wscoinpricesubscriptionparams) in [Schema](/documentation/trading-api/rest-v1/schema.md).

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

* Subscribe Ack Schema

See [`WsCoinPriceSubscriptionResult`](/documentation/trading-api/rest-v1/schema.md#wscoinpricesubscriptionresult) in [Schema](/documentation/trading-api/rest-v1/schema.md).

```typescript
interface SubscriptionResult {
  op: "subscribe";
  id: number | null; // Optional client originated request identifier sent as acknowledgment in the response.
  result: WsCoinPriceSubscriptionResult | 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": "coinPrice",
    "coins": ["vBTC"]
  }
}
```

* Example: Subscribe Ack

```json
{
  "op": "subscribe",
  "result": {
    "channel": "coinPrice",
    "coin": "vBTC"
  },
  "success": true,
  "connID": "0xcd5f500fa81f764e2eb96d4bd68695c1",
  "time_in": 1672515782130,
  "time_out": 1672515782136
}
```

## Unsubscribe Request

* Unsubscribe Schema

See [`WsCoinPriceSubscriptionParams`](/documentation/trading-api/rest-v1/schema.md#wscoinpricesubscriptionparams) in [Schema](/documentation/trading-api/rest-v1/schema.md).

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

* Unsubscribe Ack Schema

See [`WsCoinPriceSubscriptionResult`](/documentation/trading-api/rest-v1/schema.md#wscoinpricesubscriptionresult) in [Schema](/documentation/trading-api/rest-v1/schema.md).

```typescript
interface UnsubscriptionResult {
  op: "unsubscribe";
  id: number | null; // Optional client originated request identifier sent as acknowledgment in the response.
  result: WsCoinPriceSubscriptionResult | 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": "coinPrice",
    "coins": ["vBTC"]
  }
}
```

* Example: Unsubscribe Ack

```json
{
  "op": "unsubscribe",
  "result": {
    "channel": "coinPrice",
    "coin": "vBTC"
  },
  "success": true,
  "connID": "0xcd5f500fa81f764e2eb96d4bd68695c1",
  "time_in": 1672515782130,
  "time_out": 1672515782136
}
```

## Snapshot / Update Response

* Snapshot / Update Schema

See [`WsCoinPriceData`](/documentation/trading-api/rest-v1/schema.md#wscoinpricedata) in [Schema](/documentation/trading-api/rest-v1/schema.md).

```typescript
interface CoinPriceResponse {
  channel: "coinPrice";
  type: "snapshot" | "update";
  data: Array<WsCoinPriceData>;
}
```

* Example: Snapshot

```json
{
  "channel": "coinPrice",
  "type": "snapshot",
  "data": [
    {
      "E": 1781104149800,
      "i": 1,
      "a": "vBTC",
      "p": "61984.5",
      "mr": "0.9"
    },
    {
      "E": 1781104149800,
      "i": 2,
      "a": "vETH",
      "p": "1640.66",
      "mr": "0.85"
    }
  ]
}
```

* Example: Update

```json
{
  "channel": "coinPrice",
  "type": "update",
  "data": [
    {
      "E": 1781104150067,
      "i": 1,
      "a": "vBTC",
      "p": "61992",
      "mr": "0.9"
    }
  ]
}
```
