# Subscription Interface

### Events

#### 1. Kline Data Subscription

**1.1 Kline Data Subscription (v1 - Spot Only, Original)**

```javascript
socket.emit('subscribe_kline', poolId, interval);

socket.emit('subscribe_kline', 1, '1m');
```

*Returns only spot engine kline data, excluding AMM swap klines. This is the original behavior and remains the default.*

**1.2 Kline Data Subscription v2 (Aggregated)**

```javascript
socket.emit('subscribe_kline_v2', poolId, interval);

socket.emit('subscribe_kline_v2', 1, '1m');
```

*Returns aggregated kline data (spot + AMM) including AMM swap klines. This is the new enhanced version.*

#### 2. Depth Data Subscription

**2.1 Depth Data Subscription (v1 - Spot Only, Original)**

```javascript
socket.emit('subscribe_depth', poolId, precision);

socket.emit('subscribe_depth', 1, '0.00000001');
```

*Returns only spot order book depth data, excluding AMM liquidity. This is the original behavior and remains the default.*

**2.2 Depth Data Subscription v2 (Aggregated)**

```javascript
socket.emit('subscribe_depth_v2', poolId, precision);

socket.emit('subscribe_depth_v2', 1, '0.00000001');
```

*Returns aggregated depth data (spot + AMM) when AMM pools are available. This is the new enhanced version.*

#### 3.Pool Stats Data Subscription

```javascript
socket.emit('subscribe_pool_stats', poolId);

socket.emit('subscribe_pool_stats', 1);
```

#### All Pools Stats Data Subscription

```javascript
socket.emit('subscribe_all_pool_stats');
```

#### 12. Unsubscribe

```javascript
socket.emit('unsubscribe', subscriptionType, poolId, interval, precision);

socket.emit('unsubscribe', 'kline', 1, '1m');
socket.emit('unsubscribe', 'kline_v2', 1, '1m');
socket.emit('unsubscribe', 'perp_kline', 1, '1m');

socket.emit('unsubscribe', 'depth', 1, '0.00000001');
socket.emit('unsubscribe', 'depth_v2', 1, '0.00000001');
socket.emit('unsubscribe', 'perp_depth', 1, '0.00000001');

socket.emit('unsubscribe', 'trades', 1);
socket.emit('unsubscribe', 'trades_v2', 1);
socket.emit('unsubscribe', 'perp_trades', 1);

socket.emit('unsubscribe', 'amm_swap', 1);

socket.emit('unsubscribe', 'pool_stats', 1);
socket.emit('unsubscribe', 'perp_pool_stats', 1);

socket.emit('unsubscribe', 'perp_price', 1);
```

#### Unsubscribe All

```javascript
socket.emit('unsubscribe_all');
```

#### Unsubscribe All Kline

```javascript
socket.emit('unsubscribe_all_kline');
```

#### Unsubscribe All Depth

```javascript
socket.emit('unsubscribe_all_depth');
```

#### Unsubscribe All Pool Stats

```javascript
socket.emit('unsubscribe_all_pool_stats');
```

### Subscription Response

When successfully subscribing to a topic, the `subscribed` event is received:

```javascript
socket.on('subscribed', (response) => {
    console.log(response);
});
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.1dex.com/developer/websocket-streams/subscription-interface.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
