> For the complete documentation index, see [llms.txt](https://docs.hydromancer.xyz/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.hydromancer.xyz/readme/websocket/activeassetctx.md).

# activeAssetCtx

This subscription mirrors Hyperliquid activeAssetCtx exactly.

Subscribe

```json
{
    "method": "subscribe",
    "subscription": {
        "type": "activeAssetCtx",
        "coin": "<coin_symbol>"
    }
}
```

### Unsubscribe

```json
{
    "method": "unsubscribe",
    "subscription": {
        "type": "activeAssetCtx",
        "coin": "<coin_symbol>"
    }
}
```

### format

```json
{
    "channel": "activeAssetCtx",
    "seq": 1,
    "cursor": "500:1704067200000:3",
    "data": {
        "coin": "ETH",
        "ctx": {
            "oraclePx": "3230.1",
            "markPx": "3227.4",
            "midPx": "3228.25",
            "impactPxs": ["3228.2", "3228.3"],
            "openInterest": "446072.075",
            "dayNtlVlm": "543210987.65432",
            "dayBaseVlm": "157234.21098"
        }
    }
}
```

**Note:** `activeAssetCtx` uses `"channel"` instead of `"type"` as the message identifier for Hyperliquid compatibility. `impactPxs` contains the average execution price to trade impact notional (20k$ for BTC/ETH, 6k$ for others) on bid and ask.

Example:

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

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

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

ws.on('open', () => {
    console.log('WebSocket connection opened');
    console.log('Subscribing to oracleUpdates...');
    ws.send(JSON.stringify({
        "method": "subscribe",
        "subscription": {
            "type": "activeAssetCtx",
            "coin": "ETH"
        }
    }));
});

ws.on('error', (error) => {
    console.error('WebSocket error:', error);
});

ws.on('close', () => {
    console.log('WebSocket connection closed');
});

ws.on('message', (data) => {
    const msg = JSON.parse(data);
    if (msg.channel === 'activeAssetCtx') {
        console.log(msg.data)
    }
});
```

{% endtab %}

{% tab title="Python" %}

```python
import websocket
import json
import os

# Get API key from environment variable
api_key = os.environ.get('HYDROMANCER_API_KEY')
url = f'wss://api-testnet.hydromancer.xyz/ws?token={api_key}'
# url = 'wss://api.hyperliquid-testnet.xyz/ws'

def on_open(ws):
    print('WebSocket connection opened')
    print('Subscribing to oracleUpdates...')
    ws.send(json.dumps({
        "method": "subscribe",
        "subscription": {
            "type": "activeAssetCtx",
            "coin": "ETH"
        }
    }))

def on_error(ws, error):
    print(f'WebSocket error: {error}')

def on_close(ws, close_status_code, close_msg):
    print('WebSocket connection closed')

def on_message(ws, message):
    msg = json.loads(message)
    if msg.get('channel') == 'activeAssetCtx':
        print(msg.get('data'))

# Create WebSocket connection
ws = websocket.WebSocketApp(url,
                            on_open=on_open,
                            on_error=on_error,
                            on_close=on_close,
                            on_message=on_message)

# Run the WebSocket connection
ws.run_forever()
```

{% endtab %}
{% endtabs %}

#### Error messages:

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

#### Common errors

1. ```
   Connection timeout - Respond to ping messages
   ```
2. ```
   Invalid coin - Use a valid coin symbol
   ```
3. ```
   Invalid API key
   ```
