Skip to content

Quickstart

From nothing to reading markets, placing an order and streaming your account.

  • 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.
pip install stx-python

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 = us
env = demo
key_id = your-key-id
key_file = ~/.stx/demo.pem

Environment variables and keyword arguments work too; see Authentication.

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.

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.

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.

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())
v1.5.9Changelogllms.txtllms-full.txt