Skip to main content
The WebSocket gives near-real-time updates on the order book, live prices, and your own account. Public streams need no authentication; private streams are signed exactly like a REST request.
Subscribe by adding one or more stream= query parameters to the connection URL. You can combine as many as you like — including public and private together — so a client needs one connection, not several. A single stream= can also carry a comma-separated list.

Changing subscriptions on an open connection

Send a JSON message to add or drop streams without reconnecting:
Each is acknowledged with the full list of streams the connection now holds — "message": "subscribed" for a subscribe, "unsubscribed" for an unsubscribe:

Keepalive

Send the text frame ping (not JSON); the server answers with the text frame pong. A ping does not extend a public connection’s lifetime — see below. Each message is a JSON object keyed by the stream name, so one handler can switch on the key:

Connection limits

An authenticated connection — the API-key-signed upgrade on /api/v2/websocket/private — has no lifetime cap, and it can subscribe to public streams as well as private ones. A bot should open one authenticated connection and put every stream it needs on it, rather than a public connection for market data next to a private one for its account.
The 10-per-member limit counts every authenticated connection you hold, browser tabs included. A client that reconnects without closing its old socket evicts its own oldest connections, one 4008 at a time.

Channel reference

{market} is a market id; {period} a k-line period; {symbol} a product id such as ETH-USD.

Order-book format

Subscribing to {market}.ob-inc first delivers the latest snapshot (keyed {market}.ob-snap) and the increments since it, then each new increment as it happens. Levels are [price, volume] string tuples:
  • bids want YES: buy-YES orders, and sell-NO orders at the YES-equivalent price. asks offer YES: sell-YES orders, and buy-NO orders at the YES-equivalent price — a NO bid at 0.37 appears as an ask at 0.63. To show a level as a NO price, use 1 − price.
  • An increment carries the new total volume at one level, on whichever side changed. Volume "0" means the level is empty: remove it.
  • Each increment’s sequence is one more than the previous one; a snapshot carries the sequence it is current to.
If sequence is anything other than one more — a skip, or a drop to a lower number — re-subscribe (unsubscribe and subscribe to {market}.ob-inc again; subscribing again without unsubscribing sends nothing) to get a fresh snapshot and resume from there — a client that ignores the gap will drift out of sync with the book and quote prices that no longer exist.

Ticker format

{market}.ticker carries the same object as GET /api/v2/pythia/public/markets/{market}/ticker. Every figure is a string:
volume is contracts traded in 24 hours and quote_volume the cash traded. change_24h is the move of last against open as a signed fraction — "0.0333" is +3.33% — and null when there is no open price. timestamp is Unix seconds. buy and sell are the best bid and best ask in YES terms, and buy_volume and sell_volume the size resting at each. All four are null when that side of the book is empty — never "0", which would read as a price. The figures can trail fills; use {market}.trades to see each fill as it happens.

Market status format

{market}.status is pushed whenever the market’s public state changes, and says exactly what GET /api/v2/pythia/public/markets/{market} says at that moment. It replaces polling the event page for a result after a market closes.
status is the published vocabulary — active, closed, determined, settled, cancelled, voided. result is yes, no, void or null; close_at is RFC 3339 or null. event_status is the parent event’s state as /public/events serves it.

Community markets

A community market’s frame also carries where it stands in its resolution timeline. Both keys are absent from every other market’s frame.
phase_deadline is when the current phase ends, RFC 3339 UTC — for dispute_window, the end of the window — or absent when the phase has no fixed end. A phase change arrives as a new frame, like any other status change. The rules behind each phase are in Resolution and disputes.

Candle format

{market}.kline-{period} carries one candle, the same row as GET /api/v2/pythia/public/markets/{market}/k-line: [timestamp, open, high, low, close, volume], prices in YES terms, timestamp the Unix second the bucket starts. {period} is one of 1m, 5m, 15m, 30m, 1h, 2h, 4h, 6h, 12h, 1d, 3d, 1w. Buckets are counted in UTC from 1 January 1970, except weeks, which start Monday 00:00 UTC.
A frame is sent after fills move the candle, with the whole candle so far; fills that land close together arrive as one frame. A frame with a new timestamp starts the next candle; the last frame for the previous one is its final value. A bucket with no fills sends nothing. Load history with the REST route, then replace its last row with each frame of the same timestamp, or append a frame with a later one. The REST route’s last row is the candle as it stands, which can be newer than the latest frame.

Authenticating a private connection

The upgrade request is HMAC-signed like any other GET, so the signed path must include the full ?stream=… query string:
See Authentication for the canonical message.

Underlying price feed

?stream=crypto.{symbol} republishes a Coinbase-fed asset’s own feed, the source its markets settle against.
BTC-USD is not available through the API. Its price comes from Chainlink Data Streams, which Calibri licenses for display on calibri.io only, so the crypto.BTC-USD stream and the BTC-USD price history endpoints are not served to API clients. A settled window’s price to beat and final price are in the market’s price_settlement, and anyone can check them with Chainlink’s Settlement Verifier on data.chain.link. For a live feed, connect to Chainlink Data Streams with your own key.
The stream is sampled: not every price the source publishes is sent.
bucket_open is for drawing. Settlement reads the market’s settlement source — see How markets are resolved.

Private streams

Every frame below, except Balance and a void’s Contract frame (both described in their sections), always carries every key listed for it; a key that does not apply is null, never left out. Ids are numbers, decimals are strings, *_at fields are RFC 3339 UTC to the second. Order, Contract and Position frames also carry the market’s names: market_title, event_slug, event_title, outcome_labels ([yes, no]) and the token_id of the frame’s side — the same fields the REST rows carry — so you can label a row without reading its market. They are left out when the market’s names are not available. Order — one frame per event, in three shapes. Keep your own copy of each order and merge every frame into it by id, rather than replacing it. Placed:
ioc: true marks an immediate-or-cancel order — that wait will not rest on the book. client_order_id is null when you sent none. Filled, on each fill of the order:
state turns done when nothing remains. Cancelled, rejected or refunded — including the refund of an IOC remainder and an order cancelled as its signature nears expiry:
state is cancel, done or reject. Contract — your own fills, one frame per match, with the fields of your row in GET /account/contracts:
side is the outcome you traded and direction whether you bought or sold it. price is in YES terms, like the tape: for a NO fill your price is 1 − price. fee is what you paid, "0" as the maker. A void sends id, market_id, price, volume and state: "voided", with updated_at in place of created_at; match it to the fill by id. Balance — changes to the pool collateralising your orders, i.e. the mirror of your Safe:
Every balance frame carries currency, custody, balance and locked. The other keys depend on the event that sent it — a deposit’s frame, for example, has total and timestamp instead of redeemable and updated_at — so read the keys you need and ignore the rest. balance is what is spendable now, not the total — the total is balance + locked. redeemable is the winnings still to redeem from the chain; it is set on frames sent by a settlement (including a market that resolves void) or a redemption, and null otherwise — including a voided match. contract_id is set on the frame sent when the chain confirms a match’s settlement — for example a seller’s proceeds moving from pending to balance: the id of that contract (the fill’s id on the contract stream), so you can mark that fill confirmed on-chain without reading it again. It is null on every other frame. A frame with custody: "eoa" is different: it is the on-chain balance of an external wallet linked to your account, sent while you are signed in to the web app, with address, balance_raw, decimals and block_number. It is not trading balance — filter on custody: "self" for that.
Settlement does not credit a winner automatically. On-chain resolution only makes the winning outcome token redeemable; the balance moves when the position is redeemed — by you, or by auto-redeem if you turned it on. Settlement sends a balance frame with redeemable set, but balance does not change until redemption — see Redeeming winnings.
Balance updates are triggered by deposits, withdrawals, order creation (a buy locks stake plus the taker-fee reserve, unless it is post-only), cancellation, partial fills, rejection, settlement, redemption, voids and reward payouts. Position — your holding in a market, after anything changes it: a fill, an exit, settlement, or a void. Its own field set — not the same as a GET /account/positions row:
sellable_volume is what you can offer right now — volume less anything already committed to a resting sell and less pending_volume (bought shares whose match has not settled on-chain yet). contract_id is set on the frame sent when the chain confirms a match’s settlement and releases those shares: the id of that contract. It is null on every other frame. realized_pnl banks at the moment you exit, so it moves on a sale rather than waiting for the market to resolve. avg_price, realized_pnl, settled_payout and source are null when the event that sent the frame did not produce them: a settlement sends settled_payout.

Reading the tape

Each fill on {market}.trades is one trade object, with the same keys whatever kind of fill it was:
id is the fill’s id on the REST tape. price is always the YES price. match_type is mint when two buyers created new contracts, transfer when a holder sold to a buyer of the same outcome, and merge when holders of both outcomes sold into each other. On a transfer, side is the token that changed hands; it is null on a mint or merge. yes_locked / no_locked are the collateral each leg of a mint put up, null on the other two. taker_side is the outcome the aggressor bought, meaning the side that crossed the spread and paid the taker fee. It is "yes", "no", or null. A taker that sold is reported on the other outcome — selling YES is buying NO in price terms — so taker_side always says which way the fill leant on the book. In the example the taker sold YES. Without it a tape is only a list of prices. Direction inferred from the price moving says nothing about the many fills that print at the same price as the one before them, and a buy and a sell print identically.
null means unknown, not “neither”. Fills matched before taker attribution was recorded report null. Render those as unattributed — do not pick a side for them.
taker_side and side are also on the REST tape at GET /public/markets/{market}/contracts/recent, under the same rules; the REST tape has no match_type, yes_locked or no_locked.

Authentication

Signing the private upgrade request.

API overview

Base URLs and conventions.

Recurring markets

What the crypto feed is for, and what settles a window.

Fees

Why a resting order locks more than its stake.