WebSockets
Stream real-time market data without polling. WebSocket connections don't count against your rate limit.
Connection URLs
| Exchange | WebSocket URL |
|---|---|
| Hyperliquid | wss://api.paperx.co/ws |
| Uniswap | Coming soon |
Basic Connection
Python Example
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()Subscription Types
trades
Real-time trade executions for a specific coin
l2Book
Order book updates (bids and asks)
userFills
Your paper trade fills in real-time
userEvents
Account events (liquidations, funding, etc.)
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.