Quickstart
Describes stx-python 0.10.1, the current release.
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)Sample output:
user e6528824-b4e0-4ff8-bd70-36e5904738d1 account 28417940-ecef-40a9-8816-cc055d7d846f scope read_writescope 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[-1].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)Sample output:
STXNHL-26OCT101600EDMSJ-GAMEEDM bid 0.5800 offer 0.5900 pays 1.0000STXNHL-26OCT101600EDMSJ-SOGSJCMCDAVID209555-3.5 bid 0.4900 offer 0.5300 pays 1.0000next cursor: g2gDbQAAABBodIE2ul3LojBFatEY0rDzbgUB41zwLIZoA2EAbgcAANDo6IFdBmIAALhPPrices are dollar strings ("0.5800"). Bids and offers both run from the highest price to the lowest, so the best bid is the first bid and the best offer is the last offer. 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)Sample output:
placed 8f023ead-6f2d-4cf5-9931-cd217e44a2ee accepted 0.0100 1.00cancel cancelledA 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())Sample output, with one order resting on the book:
open orders: 1- Trading: batch orders, cancel many or all, expiration, cancel-on-disconnect
- WebSockets: every channel
- Errors & retries

