WebSocket
Real-time market data. No authentication required.
Connection
wss://ws.parti-oracle.pbcapps.dev/v1/ws
Subscribe
{"action": "subscribe", "channel": "book:abc123def456..."}
{"action": "subscribe", "channel": "trades:abc123def456..."}
{"action": "subscribe", "channel": "user:7yQ3mH9a..."}
Events
BookUpdate
Sent on every order book change. Includes full snapshot + live prices.
{
"type": "book_update",
"market_id": "abc123...",
"snapshot": {
"yes_bids": [{"price": 6200, "size": 500, "order_count": 3}],
"yes_asks": [{"price": 6300, "size": 200, "order_count": 1}],
"yes_price": 6250,
"no_price": 3750,
"spread": 100,
"sequence": 42
}
}
Trade
Sent on every fill.
{
"type": "trade",
"market_id": "abc123...",
"trade": {
"price": 6200,
"quantity": 100,
"taker_side": "buy",
"outcome": "yes",
"taker_fee": 15,
"builder_fee": 62,
"timestamp": 1700000000
}
}
MarketUpdate
Sent when a market is resolved or status changes.
Channels
| Channel | Events |
|---|---|
book:{market_id} |
BookUpdate |
trades:{market_id} |
Trade |
markets |
MarketUpdate (all markets) |
user:{public_key} |
Trades involving this user |
Example
const ws = new WebSocket('wss://ws.parti-oracle.pbcapps.dev/v1/ws');
ws.onopen = () => {
ws.send(JSON.stringify({ action: 'subscribe', channel: `book:${marketId}` }));
ws.send(JSON.stringify({ action: 'subscribe', channel: `trades:${marketId}` }));
};
ws.onmessage = (e) => {
const msg = JSON.parse(e.data);
if (msg.type === 'book_update') {
updatePrices(msg.snapshot.yes_price, msg.snapshot.no_price);
updateOrderBook(msg.snapshot);
}
if (msg.type === 'trade') {
addTrade(msg.trade);
}
};
Backpressure
If your client falls behind (4096 message buffer), you'll get:
{"type": "error", "code": "lagged", "message": "Dropped N messages"}
Re-fetch state via REST when this happens.