> For the complete documentation index, see [llms.txt](https://docs.kanalabs.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.kanalabs.io/spot-and-perp-apis/trading-apis/kana-perps-api/kana-perps-websocket-api.md).

# Kana Perps Websocket API

## Websocket Overview

### Supported Markets

This Websocket API provides information for the following trading markets:

<table data-header-hidden><thead><tr><th></th><th width="282"></th><th></th></tr></thead><tbody><tr><td><strong>Asset</strong></td><td><strong>Market ID</strong></td><td><strong>Description</strong></td></tr><tr><td>APT/USDC</td><td>301</td><td>Aptos-based trading market.</td></tr><tr><td>BTC/USDC</td><td>302</td><td>Bitcoin-based trading market.</td></tr><tr><td>ETH/USDC</td><td>303</td><td>Ethereum-based trading market.</td></tr></tbody></table>

### Prerequisites

#### Install Required Packages

Before you begin, install the following dependencies:

```bash
npm install ws
```

This documentation explains how to connect and receive data from the WebSocket streams:  You can connect order book  stream using client initialization code in TypeScript.

### **Endpoint URL :**

* Order Book Stream : [`wss://perps-sdk-ws.kanalabs.io/wsOrderBook`](#endpoints)

**Example Request:**\
\
`wss://perps-sdk-ws.kanalabs.io/wsOrderBook/marketId=301`\
\
Here is the steps to initialize the client code in typescript :\
\
Example code to fetch the Order Book Client Initialization Code:

```typescript
import WebSocket from 'ws';

const marketId = 'your_market_id';

const ws = new WebSocket(`wss://perps-sdk-ws.kanalabs.io/wsOrderBook?marketId=${marketId}`);

ws.on('open', () => {
    console.log('[client] Connected to the server');
    ws.send('Request data from endpoint');
});

ws.on('message', (data) => {
    console.log(`Received a message from the server:, ${data}`);
});

ws.on('close', () => {
    console.log('[client] Disconnected from the server');
});
```
