Skip to main content
This walks the full flow: verify a key, connect the stream, find an event, register for offers, quote a selection, place an order, and watch it fill.

Before you start

You need an API key, a funded account, and Python 3.10 or later with two libraries:
The magicmarkets CLI (command line interface) runs this whole flow from a terminal and is the quickest way to start. Use this guide when you want to write the code yourself.
This places a real order with real USDT. Use a small stake and a price that will not match if you only want to see the mechanics.
1

Check the key over REST

A bad key fails the WebSocket handshake with HTTP 401 and a short auth_rejected body. REST returns a JSON error with a named code, so check the key there first.
2

Connect and take the initial sync

Collect events until the sync marker. Every frame is a batch envelope, so iterate data[].
3

Register for offers on one event

Events arrive without prices. Register the one you want and offers start flowing.
4

Read a bet type off an offer

Never construct a bet type by hand for your first order. Take one the feed has already given you, with liquidity on it.
5

Create a betslip

A betslip is the first step to place an order on one selection. Create it when you are ready to place. The response has no prices yet.
6

Wait for the quote

It arrives as a pmm message on the socket you already hold. Give up if the betslip closes first.
7

Place the order

Always send a request_uuid. A retry with the same UUID cannot create a second order.
8

Watch the order

Order and bet updates arrive on the same socket.
An order starts open, can pass through pending, and finishes done or failed, at which point closed is true. Later updates can show reconciled, partial_void or full_void. A done order is filled, not settled: profit_loss lands after the event finishes.

What to add next

  • A heartbeat, if the strategy runs unattended. See Safety.
  • Error handling. Check status before reading data, and honour retry_after on a 429. See Errors and rate limits.
  • Reconnect logic. Treat the stream as lossy. On reconnect you get a fresh sync, so rebuild from that. See WebSocket stream.

The same flow with curl

Set SPORT, EVENT and BET from an offer first. The values below are examples.