Quickstart
From nothing to reading markets, placing an order and streaming your account.
Prerequisites
Section titled “Prerequisites”- Python 3.9 or newer (
python3 --version) - An API key for the exchange you are building against: a key ID and an Ed25519 private key. Environments lists the exchanges and where to get a key.
Walkthrough
Section titled “Walkthrough”Install the SDK
Section titled “Install the SDK”pip install stx-pythonSave your key
Section titled “Save your key”Save the private key as a file, for example ~/.stx/demo.pem, then create ~/.stx/credentials with a [default] profile. Set region and env to the exchange the key belongs to; the values are on Environments.
[default]region = usenv = demokey_id = your-key-idkey_file = ~/.stx/demo.pemEnvironment variables and keyword arguments work too; see Authentication.
Make your first call
Section titled “Make your first call”from stx import STX
with STX() as client: me = client.me() print("user", me.user_id, "account", me.account_id, "scope", me.scope)scope is read_only or read_write; placing orders needs read_write.
Read some markets
Section titled “Read some markets”from stx import STX
with STX() as client: page = client.markets(status="open", limit=5) for m in page: bid = m.bids[0].price if m.bids else "-" offer = m.offers[0].price if m.offers else "-" print(f"{m.symbol:<50} bid {bid:>8} offer {offer:>8} pays {m.max_price}") print("next cursor:", page.cursor)Prices are dollar strings ("0.4200"). A winning contract pays the market’s max_price.
Place and cancel an order
Section titled “Place and cancel an order”from stx import STX
with STX() as client: market = next( m for m in client.iter_markets( status="open", trading=True, sort_by="event_start", sort_direction="desc" ) if m.event_status == "scheduled" ) order = client.place_order(market.market_id, "buy", "limit", price="0.01", quantity="1") print("placed", order.id, order.status, order.price, order.quantity) print("cancel", client.cancel_order(order.id).status)A 1-cent buy for one contract, cancelled straight away.
Stream your orders
Section titled “Stream your orders”import asyncio
from stx import AsyncSTX
async def main(): async with AsyncSTX() as client: async with client.websocket() as ws: orders = await ws.orders() snapshot = await orders.wait_snapshot() print("open orders:", len(snapshot["all_orders"]["orders"]))
asyncio.run(main())- Trading: batch orders, cancel many or all, expiration, cancel-on-disconnect
- WebSockets: every channel
- Errors & retries

