Documentation · WebSocket

WebSocket API

The live event stream. One authenticated connection; events are pushed as they're ingested. Included with every key.


Endpoint

wss://stream.vera.cryptobriefing.com/v1/events

Authentication

Send your key on the Authorizationheader during the upgrade handshake. Browsers can't set arbitrary headers on WebSocket, so for browser clients we accept the key as a query parameter. Anything server-side should use the header.

bashbash
0
wscat -c wss://stream.vera.cryptobriefing.com/v1/events \
      -H 2

1
wss://stream.vera.cryptobriefing.com/v1/events?key=vera_live_xxx

Subscriptions

After connecting, send a subscribe message naming the markets you want events for. You receive a confirmation and then a stream of event messages.

client → serverjson
{
  0: 1,
  2: [3, 4],
  5: [6, 7]
}
server → clientjson
{
  0: 1,
  2: [3, 4],
  5: 6
}

Subscriptions are additive. Send another subscribe message to add markets; send unsubscribe with a market list to remove them.

client → serverjson
{ 0: 1, 2: [3] }
{ 4: 5 }
{ 6: 7 }

Event messages

Same shape as the REST Schema: one record per event. The only added field is type: "event" at the top level so your handler can route by message type.

server → clientjson
{
  0: 1,
  2: { 3: 4, ... },
  5: [ ... ],
  6: { ... }
}

Heartbeats

The server sends a ping frame every 25 seconds. Your client should respond with a pong. Most WebSocket libraries do this automatically; check yours.

If we don't receive a pong within 10 seconds, we close the connection. Your client should auto-reconnect with exponential backoff (start at 1s, max 30s, jitter ±20%).

Backfill on reconnect

On reconnect, send your last-seen event id in the first subscribe message to receive any events you missed during the gap.

client → serverjson
{
  0: 1,
  2: [3],
  4: 5
}

Backfill is capped at 1,000 events or 1 hour, whichever comes first. If the gap is larger than either, we send a backfill_truncated message and you should fall back to a REST sweep against /events?since=....

Connection limits

  • 3 concurrent connections per API key.
  • 500 markets per connection. Soft limit; over by ~10% triggers a warning, over by more drops the oldest subscriptions.
  • Use one connection per logical environment (prod / staging / research). Multiplex within the connection rather than opening more.

Reference client

vera-ws.tsts
import WebSocket from 3;

const ws = new WebSocket(4open5subscribe6polymarket_0xabc...7high8moderate9message10event11close12Vera WS closed:", code, reason.toString());
  2
});

Error frames

Protocol errors (invalid JSON, unknown action, exceeded subscription cap) come back as type: "error" messages without closing the connection. Authentication failures and rate-limit hits close the connection with a specific WebSocket close code.

Close codeReason
4001Authentication failed (invalid or revoked key)
4002Subscription would exceed connection cap
4003Account is past_due / suspended: pay outstanding invoice and reconnect
4009Rate limit on connection-open exceeded; retry after 60s
1001Server going away (planned maintenance); reconnect with backoff
1011Internal server error; reconnect with backoff