WebSocket protocol
Authenticate and subscribe
Open wss://api.matchfeed.dev/v1/stream with an Authorization: Bearer header. Browser Origin and query-string credentials are rejected. One socket carries many matches and channels. The first server frame is {"type":"ready","version":"1"}. Send JSON text. This Python example uses pip install websocket-client.
import json, os
import websocket
ws = websocket.create_connection("wss://api.matchfeed.dev/v1/stream",
header=["Authorization: Bearer " + os.environ["MATCHFEED_API_KEY"]],
suppress_origin=True)
print(ws.recv()) # ready
ws.send(json.dumps({"op":"subscribe","matches":[os.environ["MATCH_ID"]],"feeds":["A"]}))
while True:
frame = json.loads(ws.recv())
print(frame["type"], frame.get("cursor"))
Commands
| op | Payload and behavior |
|---|---|
| subscribe | matches: array of public match IDs, feeds: array of purchased channel names. Up to 512 IDs per command; send further commands on the same connection. New subscriptions receive snapshot or waiting, followed by ack. Duplicate subscriptions are idempotent. |
| unsubscribe | Same matches and feeds. Other subscriptions continue. |
| resync | Send matches and feeds already subscribed. Replaces each baseline with a current snapshot. |
| subscribe · scope=live | Paid only. Omit matches, set scope to "live" and feeds to the desired list. Follows available coverage as it appears. Use unsubscribe with scope=live to stop that scope for the named channels. |
| ping | Replies with {"type":"pong"}. Libraries should also answer WebSocket control PING with PONG. |
Reconnect and resume
{"op": "subscribe", "matches": ["mf_00000000000000000001"], "feeds": ["A", "C"], "after": {"mf_00000000000000000001": {"A": "saved-A-cursor", "C": "saved-C-cursor"}}}
Persist cursor only after applying the event, per (match_id,feed). A valid after replays later records; ack can arrive first. Without after a snapshot establishes a baseline. reset means discard that baseline and accept the next snapshot or waiting. gap means keep the last values marked stale and wait for the next snapshot. All types except snapshot/update/gap are control messages and never enter the event list. received_at is the capture timestamp; display clocks may differ. Deduplicate repeated delivered cursors; cursors are opaque and cannot be compared across streams.
Errors carry type:error, code and possibly match_id/feed. unavailable means missing coverage; quota_exceeded applies to trials (one socket and ten unique matches across all channels), scope_not_allowed rejects the trial firehose, rate_limited asks a trial to wait ten seconds between new subscribe/resync commands. Partial subscription errors leave successful pairs active. On disconnect reconnect with bounded exponential backoff; if the key or plan expires, obtain valid access first.
During a confirmed source gap, REST keeps the last data with status=stale and stale_reason=awaiting_snapshot. A fresh WebSocket subscription receives waiting with that reason until a verified replacement snapshot arrives.
Waiting, reset and gap on one channel
The following are independent JSON messages. Plain waiting means there is no deliverable baseline yet. A waiting reason of awaiting_snapshot means a gap is open. A reset rejects the previous resume cursor; discard only that match/channel baseline and await snapshot or waiting. A gap is a historical data envelope: read data.reason, retain the prior state marked stale, persist its cursor after marking the gap, and wait for the next complete snapshot. Its other documented reason is source_reconnect.
{
"type": "waiting",
"match_id": "mf_00000000000000000001",
"feed": "C"
}{
"type": "waiting",
"match_id": "mf_00000000000000000001",
"feed": "C",
"reason": "awaiting_snapshot"
}{
"type": "reset",
"match_id": "mf_00000000000000000001",
"feed": "C",
"reason": "cursor_unavailable"
}{
"type": "gap",
"match_id": "mf_00000000000000000001",
"feed": "C",
"cursor": "sample.gap",
"received_at": "2026-01-01T12:03:00Z",
"data": {
"reason": "invalid_transfer"
}
}With a valid resume cursor the server replays the actual later deliveries; even the very first one may be a naturally occurring full snapshot. Replace the whole baseline immediately. Seeing a snapshot alone does not indicate a rejected cursor. Each full envelope can carry all the events that were already present before it. Control frames have no event cursor. Validate them with the control-message schema; history and stream data use the data-envelope schema.