Skip to content

Your first order

This places a bid for Up at 50¢ on a market trading now, waits to see it rest on the book, and cancels it. It needs an API key and the signed function from that page. It also needs a registered session key and the sign_message function from Signing orders.

Take the first window from the schedule that is taking orders:

import httpx
BASE = "https://inflection.exchange"
schedule = httpx.get(f"{BASE}/api/markets/schedule", params={"limit": 10}).json()["markets"]
market = next(m for m in schedule if m["status"] in ("open", "live"))
print("trading", market["slug"])
import asyncio
import json
import secrets
import websockets
async def first_order(market_id: int, max_fee_bps: int):
client_order_id = secrets.randbelow(2**53 - 1) + 1
async with websockets.connect(
"wss://inflection.exchange/ws/trade", additional_headers=signed("GET", "/ws/trade")
) as socket:
print(json.loads(await socket.recv())) # auth_success
print(json.loads(await socket.recv())) # open_orders
await socket.send(json.dumps(sign_message({
"type": "place",
"client_order_id": client_order_id,
"market_id": market_id,
"side": "bid",
"outcome": "up",
"price_bps": 5000,
"quantity": 100,
"max_fee_bps": max_fee_bps,
})))
async for frame in socket:
message = json.loads(frame)
print(message)
if message["type"] == "order_rested":
await socket.send(json.dumps(sign_message(
{"type": "cancel", "client_order_id": client_order_id, "market_id": market_id},
)))
if message["type"] in ("order_cancelled", "order_rejected"):
break
if message["type"] == "fill" and message["remaining_quantity"] == 0:
break
asyncio.run(first_order(market["market_id"], market["taker_fee_rate_bps"]))

That order is 100 lots, one share, at 50¢: it costs $0.50 and pays $1.00 if Up wins. It signs max_fee_bps at the market’s taker_fee_rate_bps, the least the gateway accepts. See Fees.

On an empty enough book:

  1. order_accepted: the exchange took the order.
  2. order_rested: it is on the book, waiting.
  3. order_cancelled with reason: "client_request": your cancel worked.

If someone was already selling Up at 50¢ or less, you get a fill instead of, or before, order_rested. If your account cannot cover the order, you get order_rejected with reason: "insufficient_collateral". If the signature is wrong, you get order_rejected with a reason from Signing orders.

client_order_id is your name for the order, and every update about it carries it back. Use a new one for each order in a market, and never reuse one: the example draws a random number each time it runs. See Orders for order types, changing orders, and every update you can get.