# allActiveAssetCtx

{% hint style="info" %}
New endpoint - this endpoint is not a part of original Hyperliquid API and is added by us for builder convenience.
{% endhint %}

{% hint style="warning" %}

### ⚠️ This is an add-on endpoint - access has to be purchased separately.

{% endhint %}

Instead of subscribing to `activeAssetCtx` per-coin (N separate subscriptions), `allActiveAssetCtx` sends all asset contexts in a single message per snapshot tick (\~1s).

### Subscribe

```json
{
    "type": "subscribe",
    "subscription": {
        "type": "allActiveAssetCtx",
        "dex": "dex_name" // optional, filters by DEX prefix
    }
}
```

### Unsubscribe

```json
{
    "type": "unsubscribe",
    "subscription": {
        "type": "allActiveAssetCtx",
        "dex": "dex_name" // optional, must match subscribe msg
    }
}
```

### Parameters

| Parameter | Required | Description                                                                                                                                                         |
| --------- | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `dex`     | No       | Filter by DEX. `"main"` returns native coins (BTC, ETH, etc). Other values (e.g. `"hyna"`) return only coins with that prefix. Omit for all coins across all DEXes. |

### Message format

One message per snapshot tick containing all matching asset contexts:

```json
{
    "type": "allActiveAssetCtx",
    "seq": 1,
    "cursor": "0",
    "data": {
        "BTC": {
            "oraclePx": "67250.0",
            "markPx": "67248.5",
            "midPx": "67249.25",
            "impactPxs": ["67249.0", "67249.5"],
            "openInterest": "12345.678"
        },
        "ETH": {
            "oraclePx": "3230.1",
            "markPx": "3227.4",
            "midPx": "3228.25",
            "impactPxs": ["3228.2", "3228.3"],
            "openInterest": "446072.075"
        },
        "hyna:BTC": {
            "oraclePx": "67250.0",
            "markPx": "67251.2",
            "midPx": "67250.6",
            "impactPxs": ["67250.4", "67250.8"],
            "openInterest": "100.5"
        }
    }
}
```

The `data` field is a map from coin name to asset context. `impactPxs` contains the average execution price to trade impact notional (20k$ for BTC/ETH, 6k$ for others) on bid and ask.

When using the `dex` filter, only matching coins are included. For example, `"dex": "main"` would return only `BTC` and `ETH` from the above, while `"dex": "hyna"` would return only `hyna:BTC`.

### Examples

{% tabs %}
{% tab title="Javascript" %}

```javascript
const WebSocket = require('ws');

const ws = new WebSocket(`wss://api.hydromancer.xyz/ws?token=${process.env.HYDROMANCER_API_KEY}`);

ws.on('message', (data) => {
    const msg = JSON.parse(data);

    if (msg.type === 'connected') {
        ws.send(JSON.stringify({
            type: 'subscribe',
            subscription: {
                type: 'allActiveAssetCtx'
            }
        }));
    } else if (msg.type === 'ping') {
        ws.send(JSON.stringify({ type: 'pong' }));
    } else if (msg.type === 'allActiveAssetCtx') {
        const coins = Object.keys(msg.data);
        console.log(`Received ${coins.length} asset contexts`);
        // Access individual coin data:
        if (msg.data['BTC']) {
            console.log(`BTC mark: ${msg.data['BTC'].markPx}`);
        }
    }
});
```

{% endtab %}

{% tab title="Python" %}

```python
import websocket
import json
import os

def on_message(ws, message):
    msg = json.loads(message)

    if msg.get('type') == 'connected':
        ws.send(json.dumps({
            "type": "subscribe",
            "subscription": {
                "type": "allActiveAssetCtx"
            }
        }))
    elif msg.get('type') == 'ping':
        ws.send(json.dumps({'type': 'pong'}))
    elif msg.get('type') == 'allActiveAssetCtx':
        data = msg['data']
        print(f"Received {len(data)} asset contexts")
        if 'BTC' in data:
            print(f"BTC mark: {data['BTC']['markPx']}")
    elif msg.get('type') == 'error':
        print(f"Error: {msg}")

ws = websocket.WebSocketApp(
    f"wss://api.hydromancer.xyz/ws?token={os.environ.get('HYDROMANCER_API_KEY')}",
    on_message=on_message
)
ws.run_forever()
```

{% endtab %}
{% endtabs %}

#### Error messages:

```
{
    "type": "error",
    "message": "Invalid API key"
}
```

#### Common errors

1. ```
   Rate limit exceeded - allActiveAssetCtx requires add-on permission
   ```
2. ```
   Connection timeout - Respond to ping messages
   ```
3. ```
   Invalid API key
   ```


---

# 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.hydromancer.xyz/readme/websocket/allactiveassetctx.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.
