# Websocket Connection

### **Important Note:**

For all the Websocket endpoints below, pass your profile address.

To track your transactions on-chain (e.g., via **Aptos Explorer** or **Aptos Scan**), you must use your **profile address**, as all on-chain trades are executed using this profile address.

To obtain your profile address, use the `/getProfileAddress` endpoint and provide your wallet address as the `userAddress` parameter.

### How to Fetch the Profile Address:

**Example endpoint:**\
<https://perps-tradeapi.kanalabs.io/getProfileAddress?userAddress=0xd01e3a233632a41463bd6d289e99e69e1b50815c7afff710e1c992659a8722f3>\
\
**Example code:**\
[https://docs.kanalabs.io/perpetual-futures/kana-perps/api-docs/kana-perps-typescript-rest-api#id-20.-](https://docs.kanalabs.io/perpetual-futures/kana-perps/api-docs/kana-perps-typescript-rest-api#id-19.-update-stop-loss)get-profile-address

### How to subscribe websocketURL:

#### ✅ **Testnet WebSocket URL**

```typescript
wss://perpetuals-indexer-ws-develop.kanalabs.io/ws/
```

#### ✅ **Mainnet WebSocket URL**

```typescript
wss://perpetuals-indexer-ws.kana.trade/ws/
```

Connect websocket with URL

* order\_history

```
{
  "topic": "order_history",
  "address": "{{user_address}}"
}
```

* deposit\_withdraw\_history

```
{
  "topic": "deposit_withdraw_history",
  "address": "{{user_address}}"
}
```

* trade\_history

```
{
  "topic": "trade_history",
  "address": "{{user_address}}"
}
```

* positions

```
{
  "topic": "positions",
  "address": "{{user_address}}"
}
```

* open\_orders

```
{
  "topic": "open_orders",
  "address": "{{user_address}}"
}
```

* orderbook

```
{
  "topic": "orderbook",
  "market_id": "{{market_id}}"
}
```

* recent\_trades

```
{
  "topic": "recent_trades",
  "market_id": "{{market_id}}"
}
```

* live\_funding\_rate

```
{
    "topic": "live_funding_rate"
}
```

* live\_order\_history (It will update only latest single data)

```
{
  "topic": "live_order_history",
  "address": "{{user_address}}"
}
```

* live\_trade\_history (It will update only latest single data)

```
{
  "topic": "live_trade_history",
  "address": "{{user_address}}"
}
```

* best\_price

```
{
  "topic": "bestPrice"
}
```

send message like and subscribe to websocket
