Five minutes from no token to discovered market to placed order to confirmed fill. Python, copy-paste runnable, browser-free after the one-time token setup.
Find something to trade. Browse, filter by category, exclude
finished events — the markets API is public, no auth needed. See
Markets for the full list of filters.
listing = call("GET", "/api/v1/events?limit=20&exclude_ended=true&source=AGARA", auth=False)for ev in listing["events"]: print(ev["slug"], "—", ev["title"])
Once you've picked an event, fetch the full detail by its slug. The
response carries the event's markets and every outcome on each
market — including the token_id you'll trade against. Recurring
series return the live window plus their most recent cycles, not
the full history.
EVENT_SLUG = next(ev["slug"] for ev in listing["events"] if ev["is_accepting_orders"])ev = call("GET", f"/api/v1/events/{EVENT_SLUG}", auth=False)market = next(m for m in ev["markets"] if m["is_accepting_orders"])outcome = market["outcomes"][0]TOKEN_ID = outcome["token_id"]print(f"trading {market['display_label']} — {outcome['label']} → {TOKEN_ID[:12]}…")
book = call("GET", f"/trade/v1/orderbook/{TOKEN_ID}", auth=False)# Either side can be empty on a brand-new market or one that just# saw a sweep — guard before indexing.best_bid = book["bids"][0]["price"] if book["bids"] else Nonebest_ask = book["asks"][0]["price"] if book["asks"] else Noneprint(f"best bid {best_bid} / ask {best_ask}")
Buy 1 share at 0.30 collateral units. Amounts go on the wire in micro units
encoded as strings — multiply by 1,000,000, stringify. (See
Conventions for why.)
placed order 9c4a3e7d-12b4-4f8e-9a3c-d2c7f0a45e1b, status PENDING
PENDING is the initial acknowledgement — we've accepted the order and
are routing it to the exchange, not that it's filled. It may progress through
SUBMITTING and OPEN, fill immediately, or be rejected asynchronously.
Poll until it reaches a terminal status, or until you give up and
cancel. Response amounts come back as strings — wrap in int(...)
when you need to do math on them.
TERMINAL = {"MATCHED", "CANCELLED", "EXPIRED", "REJECTED", "FAILED"}DEADLINE = time.time() + 30while time.time() < DEADLINE: order = call("GET", f"/trade/v1/orders/{order_id}")["order"] filled = int(order["size_matched_micro"]) total = int(order["original_size_micro"]) print(f"status={order['status']} filled={filled}/{total}") if order["status"] in TERMINAL: break time.sleep(1.0)else: print("not filled in 30s — cancelling") call("DELETE", f"/trade/v1/orders/{order_id}")