MagicMarkets Streaming API

Real-time WebSocket stream: event discovery, live prices with stakes in USDT (updated every 2 seconds), and account updates (betslips, quotes, orders, bets, balance) on a single socket. Runs as a separate service - connect directly to the stream's WebSocket server.

GitHub OpenAPI

Operations 1

GET /v2/stream WebSocket stream #

Work with this as data

Every API here is available over the APIs.io API and to AI agents over MCP.

MCP server

One button, every client — Claude, Cursor, VS Code and the rest.

https://apis.io/mcp

Tools for apis

7 MCP tools reach this
  • find_apisBrowse and filter every API in the catalog.
  • get_api_artifactsOne API's artifacts, grouped by type.
  • get_openapiThe primary OpenAPI for this API.
  • find_similar_apisAPIs that look like this one.
  • apis_io_searchSTART HERE — APIs, providers and tags for one query, each with its total.
  • resolveTurn a domain, URL or GitHub org into the provider it belongs to.
  • find_cohortsEvery scored population of providers in the catalog.
All 92 tools →

Call it yourself

curl for this page
This API
curl "https://apis.io/api/v1/apis/magicmarkets-com:magicmarkets-com-streaming-api-api"
All apis
curl "https://apis.io/api/v1/apis?limit=25"

Calls without X-API-Key need no key. Calls with it need a paid plan — get a key.

Get an API key

Free tier, no form to fill in. Signing in shares your email address with us — we store it to create your key and to recognise you if you sign in with another provider. By signing up you are subscribing to the APIs.io and API Evangelist newsletters — you can unsubscribe from any issue. See our Privacy Policy and Terms.

A second provider on the same verified email joins the account you already have.

OpenAPI Specification

magicmarkets-com-streaming-api-api-openapi.yml Raw ↑
openapi: 3.2.0
info:
  title: MagicMarkets Streaming API
  version: 0.1.0
  description: 'REST and WebSocket API for MagicMarkets. Place orders, stream real-time

    prices, and manage your positions programmatically. ## Authentication


    Every request must be authenticated with an **API key**. Pass it in the

    `X-Api-Key` header:


    ```

    X-Api-Key:

    ```


    ### Getting an API key


    API keys are created and managed through the MagicMarkets website at

    magicmarkets.com:


    1. Go to **Settings -> API**. 2. Click **Add API Key** and give it a name. 3. Copy the key value - it is shown **once at creation**, so store it

    somewhere safe immediately. You can also revoke or rename existing keys from the same page. There is

    no endpoint in this API to manage keys - all key management happens on

    the website. ### Using a key


    Send the key on every request:


    ```bash

    curl https://magicmarkets.com/v2/xrates/ \

    -H "X-Api-Key: $MAGIC_API_KEY"

    ```


    ## Quickstart


    This walkthrough goes from zero to a placed bet: stream prices over the

    WebSocket, read a `bet_type` off the feed, quote it as a betslip, place

    an order, and watch the order update on the same socket. ### Before you start


    You need an API key (see **Authentication** above) and Python 3.9+ with

    two libraries:


    ```bash

    pip install requests websockets

    ```


    Every snippet reads its configuration from the environment:


    ```bash

    export MAGIC_API_URL="https:///v2"

    export MAGIC_WS_URL="wss:///v2/stream"

    export MAGIC_API_KEY=""

    ```


    Three concepts carry the whole flow:


    - **Two steps to a bet.** A *betslip* registers your interest in one

    selection (`POST /v2/betslips/`); its live quote then arrives as

    `["pmm", ...]` entries on the WebSocket. An *order* commits a stake

    against that quote (`POST /v2/orders/`). You always create the

    betslip first. - **`bet_type` comes from the feed.** Offers on the WebSocket carry the

    `bet_type` string ready to use - pass it to `POST /v2/betslips/`

    verbatim. You never need to construct or parse it (the grammar in

    **Sports & bet types** is reference material, not required reading). - **Stakes are USDT.** Wherever money appears it is a

    `["USDT", amount]` pair. ### Step 1 - Check your key


    Before opening the socket, prove the key works with a cheap REST call -

    a bad key fails the WebSocket upgrade with HTTP 401, so verify the key

    first:


    ```bash

    curl "$MAGIC_API_URL/xrates/" -H "X-Api-Key: $MAGIC_API_KEY"

    ```


    A `200` with `{"status": "ok", ...}` means you are good to go. ### Step 2 - Connect to the stream


    Connect with the key as a query parameter. Every frame the server sends

    is a batch envelope `{"ts": ..., "data": [...]}` - iterate `data[]` and

    dispatch on each entry''s leading type tag (see the **Streaming API**

    endpoint for the full wire format):


    ```python

    import json, os

    from websockets.sync.client import connect


    ws = connect(f"{os.environ[''MAGIC_WS_URL'']}?api_key={os.environ[''MAGIC_API_KEY'']}")


    events, synced = [], False

    while not synced:

    frame = json.loads(ws.recv())

    for entry in frame["data"]:

    if entry[0] == "event":

    events.append(entry[1]) # {"sport": ..., "event_id": ..., ...}

    elif entry[0] == "sync":

    synced = True

    ```


    After `["sync", ...]` you hold the list of currently-priced events, e.g.:


    ```json

    ["event", {"event_type": "normal", "sport": "fb",

    "event_id": "2026-06-15,1001,2002", "competition_id": 1,

    "competition_name": "England Premier League",

    "competition_country": "XE", "home": "Arsenal", "away": "Chelsea",

    "event_name": "Arsenal vs. Chelsea", "ir_status": "pre_event",

    "start_time": "2026-06-15T15:00:00Z"}]

    ```


    ### Step 3 - Register for offers on an event


    Pick an event and register.'
security:
- ApiKeyHeader: []
tags:
- name: Streaming API
  description: 'Real-time WebSocket stream: event discovery, live prices with stakes in USDT (updated every 2 seconds), and account updates (betslips, quotes, orders, bets, balance) on a single socket. Runs as a separate service - connect directly to the stream''s WebSocket server.'
paths:
  /v2/stream:
    get:
      tags:
      - Streaming API
      summary: WebSocket stream
      description: '**WebSocket endpoint** - upgrade an HTTP connection to receive

        real-time prices. This is a separate service from the REST API. ### Connection


        Authenticate with an API key:


        ```

        ws:///v2/stream?api_key=

        ```


        **Query parameters:**


        | Param | Required | Description |

        |-------|----------|-------------|

        | `api_key` | yes | API key (the `X-Api-Key` value) |

        | `lang` | no | Language code: `en` (default), `ko`, `zh-hans` |


        The server does not restrict the `Origin` header, so browser-based

        clients - including pages opened from `file://` - can connect

        directly. ### Wire format


        **Every** frame sent by the server is a batch envelope:


        ```json

        {"ts": 1586042815.269000, "data": [ , , ... ]}

        ```


        - `ts` - Unix timestamp in seconds with microsecond precision,

        stamped by the server when the frame is written. - `data` - one or more messages. The `["offer", ...]`,

        `["response", ...]`, `["event", ...]`,

        `["remove_event", ...]`, `["sync", ...]`, live-event-state and

        account-update arrays shown below are the individual `data[]`

        entries; they are never sent as bare top-level frames. Multiple messages may be batched into a single envelope - e.g. a

        register snapshot and its ok `["response", ...]` together, or offers alongside

        account updates. Batching boundaries are not semantically

        meaningful - iterate `data[]` and dispatch on each entry''s leading

        type tag (`entry[0]`); never rely on ordering, grouping, or a type

        appearing exactly once per frame. ### Initial sync


        After connecting, the server sends a snapshot of the

        currently-priced events followed by a `["sync", {...}]` marker

        whose payload carries the `session_id` of this stream (useful

        when correlating with REST errors or contacting support). Each

        event is an `["event", {...}]` entry - a flat object carrying the

        identifiers and metadata - delivered inside the envelope:


        ```json

        {"ts": 1586042815.269000, "data": [

        ["event", {"event_type": "normal", "sport": "fb", "event_id": "2026-06-15,1001,2002", "competition_id": 1, "competition_name": "England Premier League", "competition_country": "XE", "home": "Arsenal", "away": "Chelsea", "event_name": "Arsenal vs. Chelsea", "ir_status": "pre_event", "start_time": "2026-06-15T15:00:00Z"}],

        ["event", {"event_type": "normal", "sport": "tn", "event_id": "2026-06-16,501,502", ...}],

        ["event", {"event_type": "multirunner", "sport": "af", "event_id": "2026-02-23,multirunner,100364405", "competition_id": 545, "competition_name": "USA NFL", "competition_country": "US", "teams": [{"team_id": 21614, "name": "Arizona Cardinals"}, {"team_id": 21615, "name": "Atlanta Falcons"}], "event_name": "NFL Super Bowl Winner", "start_time": "2026-02-23T21:00:00Z", "end_time": "2027-02-14T21:00:00Z"}],

        ["sync", {"session_id": "..."}]

        ]}

        ```


        Two event shapes appear. A `normal` (match) event carries `home` and

        `away`. A `multirunner` (outright / futures) event has no `home`/`away`;

        instead it carries a `teams` array (`[{"team_id", "name"}, ...]`, one per

        runner) and an `end_time`. Dispatch on `event_type`; read the runner list

        from `teams` for multirunners. The snapshot is not the full fixture list: it contains only events

        that currently have live prices. The dump may span several

        envelopes; `["sync", ...]` is the last `data[]` entry of the final one. From then on, changed events are re-sent as `["event", {...}]`

        entries, and an event whose prices disappear is delivered as

        `["remove_event", {"sport": ..., "event_id": ..., ...}]`. ### Live event state


        Events that are in play may additionally produce state updates as

        `data[]` entries. Payloads are sport-specific; the football shapes:


        ```json

        ["event_time", {"sport": "fb", "event_id": "...", "time": ["1h", 23]}]

        ["event_score", {"sport": "fb", "event_id": "...", "score": [1, 0]}]

        ["event_red_cards", {"sport": "fb", "event_id": "...", "score": [0, 1]}]

        ```


        - `time` - `[period, minutes]`, where the football periods are

        `"1h"`, `"2h"` and `"ht"`; `null` when no clock is available.'
      parameters:
      - name: api_key
        in: query
        required: true
        schema:
          type: string
        description: API key (the `X-Api-Key` value)
      - name: lang
        in: query
        schema:
          type: string
          enum:
          - en
          - ko
          - zh-hans
          default: en
        description: Language for event/competition names
      responses:
        '101':
          description: Switching protocols - WebSocket connection established
        '400':
          description: Refused at the handshake - `api_key` missing or `lang` invalid.
        '401':
          description: Refused at the handshake - the key was not accepted.
        '503':
          description: Refused at the handshake - the server cannot accept connections right now; retry with backoff.
        default:
          description: 'Failures are delivered in-band as `["response", {"status": "error", "code": ...}]` entries inside the `{"ts": ..., "data": [...]}` envelope on the open WebSocket, or by silent TCP close - see the **Errors** section above.'
      operationId: getV2Stream
      x-operation-id-source: derived
components:
  securitySchemes:
    ApiKeyHeader:
      type: apiKey
      in: header
      name: X-Api-Key
      description: API key created from the magic-markets website