MagicMarkets Account API
Account-level information: current balance, open stake, and smart credit, all in USDT.
Account-level information: current balance, open stake, and smart credit, all in USDT.
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-account-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 Account 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: Account
description: 'Account-level information: current balance, open stake, and smart credit, all in USDT.'
paths:
/v2/balance/:
get:
tags:
- Account
summary: Account balance
description: Returns the authenticated user's current balance, total stake on open bets, and smart credit. All values are `["USDT", amount]` tuples. The same three figures are pushed on the stream as the `balance` message; `open_stake` is positive.
responses:
'401':
$ref: '#/components/responses/Error401'
'403':
$ref: '#/components/responses/Error403'
'429':
$ref: '#/components/responses/Error429'
'500':
$ref: '#/components/responses/Error500'
'200':
description: Account balance
content:
application/json:
schema:
$ref: '#/components/schemas/BalanceEnvelope'
examples:
with_smart_credit:
summary: Account with smart credit
value:
status: ok
data:
balance:
- USDT
- 10000.1
open_stake:
- USDT
- 152.55
smart_credit:
- USDT
- 1000.0
without_smart_credit:
summary: Account without smart credit
value:
status: ok
data:
balance:
- USDT
- 10000.1
open_stake:
- USDT
- 152.55
smart_credit: null
operationId: getV2Balance
x-operation-id-source: derived
components:
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
Error403:
description: Authorization failed - the key is valid but cannot perform this action.
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorEnvelope'
example:
status: error
code: forbidden
data: null
schemas:
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.
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
BalanceEnvelope:
type: object
required:
- status
- data
properties:
status:
type: string
enum:
- ok
data:
$ref: '#/components/schemas/BalanceResponse'
BalanceResponse:
type: object
required:
- balance
- open_stake
- smart_credit
properties:
balance:
$ref: '#/components/schemas/StakeTuple'
description: Current account balance
open_stake:
$ref: '#/components/schemas/StakeTuple'
description: Total stake on open bets, positive
smart_credit:
oneOf:
- $ref: '#/components/schemas/StakeTuple'
- type: 'null'
description: Extra funds available for betting on top of the balance, equal to the amount the account is expected to win from the bets already placed. Null when the account has no smart credit.
securitySchemes:
ApiKeyHeader:
type: apiKey
in: header
name: X-Api-Key
description: API key created from the magic-markets website