activeAssetCtx
Real-time stream of oracle-, mid- and mark prices for an asset. Sends updates every second.
Last updated
{
"type": "activeAssetCtx",
"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"
}
}
}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)
}
});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(){
"type": "error",
"message": "Invalid API key"
}Connection timeout - Respond to ping messagesInvalid coin - Use a valid coin symbolInvalid API key