Skip to main content
The Sportrix Data WebSocket stream delivers live scores and statistics in real time — no polling required. As soon as a match state changes, you receive the full updated snapshot. Accessing the WebSocket stream requires the live_scores_statistics scope. Endpoint: wss://scores.sportrixdata.com/v1/stream
1
Connect and authenticate
2
Open a WebSocket connection to the stream endpoint. You can authenticate with either a key query parameter (convenient for browser clients that can’t set headers) or the X-API-Key header.
3
Using a query parameter:
4
wss://scores.sportrixdata.com/v1/stream?key=sk_your_api_key_here
5
Using a header (server-to-server):
6
X-API-Key: sk_your_api_key_here
7
The connection handshake is rejected with HTTP 401 if your key is missing, invalid, disabled, expired, or if it doesn’t have the live_scores_statistics scope. Check that your key has the right scope before debugging connection issues.
8
Subscribe to a match
9
Once connected, send a JSON control message to start receiving updates for a match. Use the match_id from the REST catalog (GET /matches, GET /matches/{id}, etc.).
10
{"action": "subscribe", "match_id": 41282}
11
The server immediately responds with a snapshot frame containing the current full state of the match. After that, you’ll receive an update frame every time the match state changes.
12
To stop receiving updates for a match, send an unsubscribe message:
13
{"action": "unsubscribe", "match_id": 41282}
14
Handle server frames
15
Every message from the server is a JSON object with an op field identifying the frame type:
16
opWhen sentFieldssnapshotImmediately after a successful subscribedata: full live snapshot objectupdateWhenever subscribed match state changesdata: full live snapshot objecterrorOn a bad control message or invalid subscriptionerror: human-readable reason
17
Example snapshot frame:
18
{"op": "snapshot", "data": {"match_id": 41282, "status": "live", "score": {"home": 3, "away": 2}, "..."  : "..."}}
19
Example error frame:
20
{"op": "error", "error": "match not live or not found"}
21
The data object always includes match_id, so you can route incoming frames correctly when multiplexing multiple matches on a single connection.

Python example

The example below uses the websocket-client library to connect, subscribe to a match, and print a live score line on every update.
import json, websocket  # websocket-client

ws = websocket.create_connection(
    "wss://scores.sportrixdata.com/v1/stream?key=sk_your_api_key_here"
)
ws.send(json.dumps({"action": "subscribe", "match_id": 41282}))
while True:
    msg = json.loads(ws.recv())
    if msg["op"] in ("snapshot", "update"):
        d = msg["data"]
        clock = d["clock"]
        print(f'{d["home"]} {d["score"]["home"]}-{d["score"]["away"]} {d["away"]} '
              f'[{clock["minute"]}:{clock["second"]:02d} {clock["period"]}] {d["phase"]["label"]}')
    elif msg["op"] == "error":
        print("error:", msg["error"])

Multiplexing multiple matches

A single WebSocket connection can track any number of matches simultaneously. Send a subscribe message for each match you want to follow — there’s no need to open a separate connection per match. Because every data object carries match_id, you can always tell which match an incoming frame belongs to.
If you only need live scores and the match clock (not full statistics), REST polling on GET /matches/{id}/live may be simpler and only requires the live_scores scope. Use the WebSocket when you need sub-second latency or want to stream stats to a live display.