MagicMarkets Market data API
Event and market discovery over REST. Entries have the same shape as the stream's `event` and `offer` entries. For live prices, use the streaming API: it pushes each change as it happens.
Event and market discovery over REST. Entries have the same shape as the stream's `event` and `offer` entries. For live prices, use the streaming API: it pushes each change as it happens.
Every API here is available over the APIs.io API and to AI agents over MCP.
One button, every client — Claude, Cursor, VS Code and the rest.
https://apis.io/mcp
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.curl "https://apis.io/api/v1/apis/magicmarkets-com:magicmarkets-com-market-data-api"
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.
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: 3.2.0
info:
title: MagicMarkets Market data 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: Market Data
description: 'Event and market discovery over REST. Entries have the same shape as the stream''s `event` and `offer` entries. For live prices, use the streaming API: it pushes each change as it happens.'
paths:
/v2/events/:
get:
tags:
- Market Data
summary: List events
description: 'Lists the events that currently have prices. Each entry is the object the stream sends as `["event", {...}]`.
For price-sensitive work, use the streaming API: it pushes each change as it happens.
`ir_status` keeps the events in running (`in_running`) or not yet started (`pre_event`), the same values each event carries.
`event_type` gives the shape. A `normal` (match) event has `home` and `away`. A `multirunner` (outright) event has `teams` and `end_time`.
Page with `limit` and `after`: pass the previous page''s last `"{sport},{event_id}"` as `after`. A page shorter than `limit` is the last one. The response has no total count.
`event_id` and `competition_id` filters need `sport`; a request without it gets a 400. Every entry has its `sport`, so a follow-up call can always supply it. Paging without filters needs no `sport`.
A filter that matches no event returns an empty `data`. This includes a sport, competition or event that has no prices at the moment. Each `event_id` must have the form an event carries, such as `2026-06-15,1001,2002`; any other form gets a 400.'
parameters:
- name: sport
in: query
description: Sport codes to keep. Repeatable, up to 100 values; omit for every sport. Required alongside `event_id` or `competition_id`. See "Sports & bet types" in the introduction.
schema:
type: array
items:
type: string
maxItems: 100
example:
- fb
- name: competition_id
in: query
description: Competitions to keep. Repeatable, up to 100 values; omit for every competition. Requires `sport`.
schema:
type: array
items:
type: integer
minimum: 0
maximum: 2147483647
maxItems: 100
- name: event_id
in: query
description: Events to keep. Repeatable, up to 100 values; omit for every event. Requires `sport`. Each value is an event's `event_id`, such as `2026-06-15,1001,2002`; any other form gets a 400.
schema:
type: array
items:
type: string
pattern: ^\d{4}-\d{2}-\d{2},[^,]+,[^,]+$
maxItems: 100
- name: lang
in: query
description: Language for competition and team names.
schema:
type: string
enum:
- en
- zh-hans
- ko
default: en
- name: limit
in: query
description: Events per page.
schema:
type: integer
minimum: 1
maximum: 5000
default: 500
- name: after
in: query
description: Cursor - the previous page's last `"{sport},{event_id}"`.
schema:
type: string
example: fb,2026-06-15,1001,2002
- name: start_time_from
in: query
description: Keep events starting at or after this instant, 1970 or later. An event whose start time is unknown is never inside a window.
schema:
type: string
format: date-time
example: '2026-06-15T00:00:00Z'
- name: start_time_to
in: query
description: Keep events starting before this instant, 1970 or later. The window is half-open, so an event starting exactly at this instant is excluded.
schema:
type: string
format: date-time
example: '2026-06-16T00:00:00Z'
- name: ir_status
in: query
description: Keep events with this `ir_status`. Omit for both.
schema:
type: string
enum:
- pre_event
- in_running
responses:
'400':
description: Invalid query parameter.
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorEnvelope'
example:
status: error
code: validation_error
data:
validation_errors:
sport:
- sport is required when filtering by event_id or competition_id
'401':
$ref: '#/components/responses/Error401'
'403':
$ref: '#/components/responses/Error403Feed'
'429':
$ref: '#/components/responses/Error429'
'500':
$ref: '#/components/responses/Error500'
'503':
$ref: '#/components/responses/Error503Feed'
'200':
description: Events with prices
content:
application/json:
schema:
$ref: '#/components/schemas/EventListEnvelope'
examples:
normal:
summary: Match event
value:
status: ok
data:
- 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'
multirunner:
summary: Outright event
value:
status: ok
data:
- 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
ir_status: pre_event
start_time: '2026-02-23T21:00:00Z'
end_time: '2027-02-14T21:00:00Z'
operationId: getV2Events
x-operation-id-source: derived
/v2/offers/:
get:
tags:
- Market Data
summary: List offers for an event
description: 'Returns the stake available at each price, for each market on the named events. Each entry is the object the stream sends as `["offer", {...}]`.
Each price level''s `updated_ts` tells how long its price has stood unchanged; a price unchanged for hours may no longer be available.
A reply can be about 4 seconds behind the live prices: the stream updates every 2 seconds, and a client may cache the response for 2 seconds (`Cache-Control: private, max-age=2`). For live prices, register the event on the stream with `register_event`.
`sport` and `event_id` are required, with up to 20 events per request. `GET /v2/events/` lists them.
`bet_type` limits the response to the named markets. It takes the same strings as `POST /v2/betslips/`, so a `bet_type` from here goes into a betslip unchanged.
`market_type` keeps the named market families, such as `ah`, `ou` or `wdw`. `min_liquidity` keeps a market when its `max` stakes, added up across its `price_list`, come to at least that many USDT.
Offers come back in `event_id` order, then `bet_type` order. Page with `limit` and `after`: pass the previous page''s last `"{event_id},{bet_type}"` as `after`. A page shorter than `limit` is the last one. Each page is read when it is requested, so for a consistent view of an event, use the stream.
Markets with no available stake are left out. `for` and `against` on one selection are two markets, each with its own `bet_type`. For a sport your account is not enabled for, the list is empty, as on the stream.
An event that has no prices at the moment, or that the feed does not know, returns no offers. The other events in the request still come back. Each `event_id` must have the form an event carries, such as `2026-06-15,1001,2002`; any other form gets a 400.'
parameters:
- name: sport
in: query
required: true
description: Sport code. See "Sports & bet types" in the introduction.
schema:
type: string
example: fb
- name: event_id
in: query
required: true
description: Events to price. Repeatable, up to 20 per request. Each value is an event's `event_id`, such as `2026-06-15,1001,2002`; any other form gets a 400.
schema:
type: array
items:
type: string
pattern: ^\d{4}-\d{2}-\d{2},[^,]+,[^,]+$
minItems: 1
maxItems: 20
example:
- 2026-06-15,1001,2002
- name: bet_type
in: query
description: Markets to keep. Repeatable, up to 100 values; omit for every market on the event. See "Sports & bet types" in the introduction.
schema:
type: array
items:
type: string
maxItems: 100
- name: market_type
in: query
description: Market families to keep, as in an offer's `market_type`. Repeatable, up to 100 values; omit for every family.
schema:
type: array
items:
type: string
maxItems: 100
example:
- ah
- ou
- name: min_liquidity
in: query
description: USDT. Keep markets whose `max` stakes, added up across the `price_list`, come to at least this.
schema:
type: number
minimum: 0
example: 250
- name: limit
in: query
description: Offers per page.
schema:
type: integer
minimum: 1
maximum: 5000
default: 500
- name: after
in: query
description: Cursor - the previous page's last `"{event_id},{bet_type}"`.
schema:
type: string
example: 2026-06-15,1001,2002,for,ah,h,1
responses:
'400':
description: Missing or invalid query parameter.
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorEnvelope'
examples:
missing_event:
summary: event_id omitted
value:
status: error
code: validation_error
data:
validation_errors:
event_id:
- Field required
too_many_events:
summary: More than 20 events requested
value:
status: error
code: validation_error
data:
validation_errors:
event_id:
- List should have at most 20 items after validation, not 21
'401':
$ref: '#/components/responses/Error401'
'403':
$ref: '#/components/responses/Error403Feed'
'429':
$ref: '#/components/responses/Error429'
'500':
$ref: '#/components/responses/Error500'
'503':
$ref: '#/components/responses/Error503Feed'
'200':
description: Offers for the named events
content:
application/json:
schema:
$ref: '#/components/schemas/OfferListEnvelope'
example:
status: ok
data:
- sport: fb
event_id: 2026-06-15,1001,2002
bet_type: for,ah,h,1
market_type: ah
in_running: false
price_list:
- effective:
price: 2.0
min: null
max:
- USDT
- 150.0
- effective:
price: 1.99
min: null
max:
- USDT
- 80.0
operationId: getV2Offers
x-operation-id-source: derived
components:
schemas:
EventListEnvelope:
type: object
required:
- status
- data
properties:
status:
type: string
enum:
- ok
data:
$ref: '#/components/schemas/EventList'
OfferPriceLevel:
allOf:
- $ref: '#/components/schemas/PriceLevel'
- type: object
required:
- updated_ts
properties:
updated_ts:
type: integer
description: Unix time in seconds, to the minute, of the most recent update of any quote that still backs this price. No quote at this price has changed for at least `now - updated_ts`. A restart of the service can reset it to the restart time.
OfferListEnvelope:
type: object
required:
- status
- data
properties:
status:
type: string
enum:
- ok
data:
$ref: '#/components/schemas/OfferList'
Event:
type: object
description: 'An event that currently has prices, identical to the stream''s `event` payload. `event_type` gives the shape: `normal` has `home` and `away`, `multirunner` has `teams` and `end_time`.'
required:
- event_type
- sport
- event_id
- competition_id
- competition_name
- competition_country
- event_name
- ir_status
- start_time
properties:
event_type:
type: string
enum:
- normal
- multirunner
sport:
type: string
description: Sport code
event_id:
type: string
competition_id:
type: integer
competition_name:
type: string
competition_country:
type: string
description: Country code of the competition, for example `US`, or `XE` for England.
home:
type:
- string
- 'null'
description: Normal events only
away:
type:
- string
- 'null'
description: Normal events only
teams:
description: Runner list (multirunner events only)
oneOf:
- type: array
items:
type: object
required:
- team_id
- name
properties:
team_id:
type: integer
name:
type: string
- type: 'null'
end_time:
type:
- string
- 'null'
format: date-time
description: Race end time (multirunner events only)
event_name:
type:
- string
- 'null'
ir_status:
type: string
enum:
- pre_event
- in_running
start_time:
type:
- string
- 'null'
format: date-time
ErrorEnvelope:
type: object
description: Standard error response. The shape of `data` varies by `code` - see the **Errors** section in the introduction and the named examples on each endpoint's error responses.
required:
- status
- code
properties:
status:
type: string
enum:
- error
code:
type: string
description: Stable machine-readable error code (e.g. `validation_error`, `not_found`, `forbidden`).
example: validation_error
data:
description: Variable. Null, string, or object - see examples.
OfferList:
type: array
description: One entry per market.
items:
$ref: '#/components/schemas/Offer'
PriceLevel:
type: object
required:
- effective
properties:
effective:
type: object
required:
- price
- min
- max
properties:
price:
type: number
description: Decimal price
min:
oneOf:
- $ref: '#/components/schemas/StakeTuple'
- type: 'null'
description: Minimum stake at this price level, or null
max:
oneOf:
- $ref: '#/components/schemas/StakeTuple'
- type: 'null'
description: Maximum stake at this price level, or null
StakeTuple:
type: array
description: '[currency, amount] - e.g. ["USDT", 115.38]'
prefixItems:
- type: string
description: Currency code (always USDT in responses)
- type: number
description: Amount
items:
type:
- string
- number
minItems: 2
maxItems: 2
EventList:
type: array
description: Events that currently have prices.
items:
$ref: '#/components/schemas/Event'
Offer:
type: object
description: The stake available at each price for one market, identical to the stream's `offer` payload.
required:
- sport
- event_id
- bet_type
- market_type
- in_running
- price_list
properties:
sport:
type: string
event_id:
type: string
bet_type:
type: string
description: 'The market and side: market type, line, outcome and `for` or `against`. `POST /v2/betslips/` accepts it as is.'
market_type:
type: string
description: Market family the bet type belongs to (e.g. `ah`, `wdw`, `ou`).
in_running:
type: boolean
description: Whether the event was in running when this offer was priced.
price_list:
type: array
description: Prices sorted descending (best price first).
items:
$ref: '#/components/schemas/OfferPriceLevel'
responses:
Error401:
description: Authentication failed - API key missing, malformed, or rejected.
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorEnvelope'
example:
status: error
code: auth_error
data:
detail: Authentication credentials were not provided.
Error500:
description: Unexpected internal error. Quote `data[1]` (the token) when contacting support.
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorEnvelope'
example:
status: error
code: server_error
data:
- 'An error has occurred, token:'
- ABC123abc456DEF789gh
Error429:
description: Rate limit hit. Honour the `Retry-After` header.
headers:
Retry-After:
description: Seconds to wait before retrying.
schema:
type: integer
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorEnvelope'
example:
status: error
code: throttled
data:
message: Request was throttled. Expected available in 12 seconds.
retry_after: 12
Error503Feed:
description: '`warming`: the feed is loading its market data or customer records; retry with backoff. A body of `{ "detail": "Service unavailable" }` without the envelope means an upstream service could not be reached; retry with backoff.'
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorEnvelope'
example:
status: error
code: warming
data: null
Error403Feed:
description: '`invalid_customer`: the feed has no record of your account; contact support, because a retry gets the same answer. `forbidden`: the key is valid but cannot perform this action.'
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorEnvelope'
example:
status: error
code: invalid_customer
data: null
securitySchemes:
ApiKeyHeader:
type: apiKey
in: header
name: X-Api-Key
description: API key created from the magic-markets website