wss://api.pegana.xyz/v1/ws
Open a connection
PegFeed / connectPegFeed
(@peganahq/sdk-ts) and Python peg_feed() (pegana-sdk). Works from the browser
too (globalThis.WebSocket), Node, and Bun.
No auth, no key. Origin header is checked against an allowlist —
https://pegana.xyz, https://www.pegana.xyz, http://localhost:3000 by default.
Add more origins via the CORS_EXTRA_ORIGINS env var on self-hosted instances.
Message shapes
All messages are JSON, single-line per frame. Theop field discriminates.
Server → client: state update
state; to react
only to transitions, compare payload.state with the last value you saw for that asset.
The envelope carries the asset symbol; payload carries the current state, the
smoothed discount (raw sign: 1 − market / intrinsic, positive = below fair value), the
two underlying values (intrinsic_usd, market_usd), and updated_at. There is no
previous_state or confidence field on this frame — fetch the prior state from
your own last-seen value, and use /v1/assets/{symbol}/state
for the confidence score.
Two optional details on update frames:
market_observed_atis a nullable string in the same millisecond-precision UTC format asupdated_at(YYYY-MM-DDTHH:MM:SS.mmmZ). It appears only when the server has the dark-market gate enabled, and tells you when the market price was last observed.state_reasonexplains anUNKNOWNstate; see the table below.
market_reference_divergence, depth_below_floor and premium_hold_timeout come from guards that are off by default. market_unavailable can appear without any guard when the market feed has gone quiet, and the engine can also emit it when its dark-market guard (off by default) is switched on. Treat any state_reason you do not recognise as “state unknown, reason new”.
Values use the same wire format as REST: decimals are strings with trailing zeros
trimmed, discount has the same 6-decimal precision /v1/assets serves, and
timestamps are RFC 3339 UTC with millisecond precision.
The stream covers every asset the engine computes, which can include assets that are not
listed on GET /v1/assets (for example xSOL, which is computed but kept off the peg
surface). If you only care about listed assets, filter frames against the symbols you got
from GET /v1/assets.
Server → client: heartbeat
Server → client: error
Client → server: ping
{ "op": "pong" }. Optional — heartbeats already keep the
connection alive on most NAT/proxy configurations.
Client → server: subscribe / unsubscribe
msg.asset. Per-asset subscription is
planned for v2.
What the server answers today, so your parser is not surprised:
-
subscribeis acknowledged with anupdateframe whoseassetis the literal string"system"and whosepayloadhas nostate:Skip frames withasset === "system"(or withoutpayload.state) before treating a frame as a peg reading, otherwise you will record a phantom asset namedsystem. -
unsubscribeis answered with{ "op": "pong" }. -
A frame that is not valid JSON or has an unknown
opgets anerrorframe ("msg": "malformed: …"); the connection stays open.
Connection limits
- Per-IP cap: 20 concurrent connections. Beyond that, handshakes return
429. - Handshake budget: 30 accepted handshakes per minute per address. Exceeding it returns
429withws_rate_limitedand aRetry-Afterheader. A connection rejected by a concurrency cap does not use this budget. - Client messages: at most 4 KiB per message and frame. A
subscriberequest accepts at most 256 asset names; a larger list receives anerrorframe. - Capacity: above 10,000 open sockets in total the server answers new handshakes with
503; retry with backoff. - Slow readers: a client that cannot receive an outbound frame within 10 seconds is disconnected.
- Idle timeout: if the server receives nothing from your client for 120 seconds, it
sends a WebSocket protocol ping and closes the connection if no frame arrives within the
next 30 seconds. Standard clients (browser
WebSocket,ws,websockets) answer protocol pings automatically, so they stay connected indefinitely; a hand-rolled client must reply to the ping or send its own{ "op": "ping" }at least every two minutes. - Shared IPs: IPv6 addresses are grouped by their /64 prefix. The cap is per source
address or IPv6 /64, so every open Pegana dashboard tab, script and
notebook behind the same NAT or office network counts toward the same 20. If you get
429while developing, close other tabs or connections on that network first.
Reconnect strategy
Recommended client logic:What about historical data?
The WebSocket is stream-only. For history, use/v1/assets/{symbol}/history. A common pattern is to fetch the
last 24h via REST on connect, then maintain real-time via WebSocket.
Next
REST API
Poll state, history and audit receipts.
MCP for agents
Native MCP tool for Claude, Cursor, Cline.