Real-Time Streaming

WebSocket API

Subscribe to real-time market data, order updates, and account events. Same format as Hyperliquid's WebSocket API.

Connection

Public Endpoint (Market Data)

wss://api.paperx.co/v1/exchanges/hyperliquid/ws

Authenticated Endpoint (User Data)

wss://api.paperx.co/v1/exchanges/hyperliquid/ws/user?token=YOUR_API_KEY

Available Subscriptions

allMids

Real-time mid prices for all assets. Updates every 500ms.

{"method": "subscribe", "subscription": {"type": "allMids"}}

l2Book

Order book updates for a specific coin. Updates every 250ms.

{"method": "subscribe", "subscription": {"type": "l2Book", "coin": "BTC"}}

trades

Real-time trade feed for a specific coin.

{"method": "subscribe", "subscription": {"type": "trades", "coin": "ETH"}}

orderUpdates

Auth Required

Your order status changes (filled, cancelled, etc).

{"method": "subscribe", "subscription": {"type": "orderUpdates"}}

userFills

Auth Required

Your trade fills in real-time.

{"method": "subscribe", "subscription": {"type": "userFills"}}

userFunding

Auth Required

Funding payments for your positions.

{"method": "subscribe", "subscription": {"type": "userFunding"}}

JavaScript Example

const ws = new WebSocket('wss://api.paperx.co/v1/exchanges/hyperliquid/ws');

ws.onopen = () => {
  console.log('Connected to PaperExchange WebSocket');
  
  // Subscribe to BTC price updates
  ws.send(JSON.stringify({
    method: 'subscribe',
    subscription: { type: 'allMids' }
  }));
  
  // Subscribe to BTC order book
  ws.send(JSON.stringify({
    method: 'subscribe',
    subscription: { type: 'l2Book', coin: 'BTC' }
  }));
};

ws.onmessage = (event) => {
  const data = JSON.parse(event.data);
  
  if (data.channel === 'allMids') {
    console.log('Price update:', data.data.mids);
  }
  
  if (data.channel === 'l2Book') {
    console.log('Order book:', data.data);
  }
};

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

ws.onclose = () => {
  console.log('Disconnected from WebSocket');
};

Python Example

import asyncio
import websockets
import json

async def connect():
    uri = "wss://api.paperx.co/v1/exchanges/hyperliquid/ws"
    
    async with websockets.connect(uri) as ws:
        # Subscribe to all mid prices
        await ws.send(json.dumps({
            "method": "subscribe",
            "subscription": {"type": "allMids"}
        }))
        
        # Listen for messages
        async for message in ws:
            data = json.loads(message)
            if data.get("channel") == "allMids":
                print(f"BTC: {data['data']['mids'].get('BTC', 'N/A')}")

asyncio.run(connect())

Message Format

Subscription Response

{
  "channel": "subscriptionResponse",
  "data": {
    "method": "subscribe",
    "subscription": {"type": "allMids"}
  }
}

Price Update (allMids)

{
  "channel": "allMids",
  "data": {
    "mids": {
      "BTC": "98500.50",
      "ETH": "3450.25",
      "SOL": "185.30"
    }
  }
}

Order Book Update (l2Book)

{
  "channel": "l2Book",
  "data": {
    "coin": "BTC",
    "levels": [
      [{"px": "98500.00", "sz": "1.5"}, {"px": "98499.00", "sz": "2.3"}],
      [{"px": "98501.00", "sz": "0.8"}, {"px": "98502.00", "sz": "1.2"}]
    ]
  }
}