WebSockets
Stream real-time market data without polling. WebSocket connections don't count against your rate limit.
Connection URLs
| Exchange | WebSocket URL |
|---|---|
| Hyperliquid | Public (market data) wss://api.paperx.co/v1/exchanges/hyperliquid/wsPrivate (user data) wss://api.paperx.co/v1/exchanges/hyperliquid/ws/user?apiKey=YOUR_KEY |
| Uniswap | Coming soon |
Basic Connection
import websocket
import json
def on_message(ws, message):
data = json.loads(message)
print(f"Received: {data}")
def on_open(ws):
# Subscribe to BTC trades
ws.send(json.dumps({
"method": "subscribe",
"subscription": {"type": "trades", "coin": "BTC"}
}))
ws = websocket.WebSocketApp(
"wss://api.paperx.co/ws",
header={"X-API-Key": "pe_your_api_key"},
on_message=on_message,
on_open=on_open
)
ws.run_forever()Public Subscription Types
No authentication required. Perfect for market data dashboards and price alerts.
allMids
All mid prices for every asset (updates ~500ms)
l2Book
Order book depth (requires coin param)
trades
Real-time trades for a coin
candle
OHLCV candles (coin + interval)
activeAssetCtx
Funding, OI, mark/oracle price for a coin
bbo
Best bid/offer stream
Private Subscription Types
Require a valid API key. These channels mirror Hyperliquid 100%.
orderUpdates
Order status changes (open/filled/cancelled)
userFills
Your fills (supports aggregateByTime)
userEvents
All account events (fills, funding, liquidations)
userFunding / userFundings
Funding payments (both singular + plural variants)
webData2 / webData3
Clearinghouse state (legacy + current)
notification
System notifications (margin alerts, billing, etc.)
twapStates
TWAP order status + progress
clearinghouseState
Direct clearinghouse subscription
openOrders
Live snapshot of all open orders
userTwapSliceFills
TWAP slice execution feed
userTwapHistory
Historical TWAP execution summary
userNonFundingLedgerUpdates
Non-funding ledger events
activeAssetData
Per-asset detail (coin + user context)
Best Practices
Implement reconnection logic
WebSocket connections can drop. Always implement automatic reconnection with exponential backoff.
Handle heartbeats
Send periodic pings to keep the connection alive. The server will disconnect idle connections.