Skip to main content
Pre-release — 0.1.x. Sync HTTP, async HTTP, and WebSocket clients with typed Pydantic v2 response models are available today. API-key auth is in progress.
stx-python is the official Python SDK for the SportsX trading exchange. It wraps the GraphQL HTTP API and Phoenix WebSocket channels behind a small, ergonomic surface:
  • STX — synchronous GraphQL client
  • AsyncSTX — asyncio-native GraphQL client (same surface as STX)
  • STXWebSocket — Phoenix channels client with reconnect, heartbeat, and resubscribe baked in
One package, three clients, one shared authentication singleton.
pip install stx-python
from stx import STX, Selection

client = STX(region="ontario", env="production",
             email="you@example.com", password="...")
markets = client.marketInfos(selections=Selection("marketId", "status"))

Where to go next

Quickstart

Install, authenticate, and make your first call in under five minutes.

Installation

Supported Python versions, optional extras, and platform notes.

Authentication

Email/password login, 2FA, env vars, and profile files.

Configuration

Regions, environments, ~/.stx/credentials profiles, and schema pinning.

Market data

Query markets, orderbooks, and event metadata.

Trading

Place, cancel, and inspect orders; fetch positions and fills.

WebSockets

Subscribe to Phoenix channels for real-time order and market updates.

Async

The same API as STX, awaitable — for bots and high-fanout services.

Errors & retries

Exception hierarchy, the built-in retry policy, and how to override it.

API reference (compact)

Every operation on one page — Ctrl-F index to all 64 queries and mutations.

API reference (by category)

Per-category pages with parameters tables and examples for each op.

Design goals

The SDK should feel like writing Python, not like calling a GraphQL API. You should be able to get useful results without knowing what a Selection or a DSL field is.
  1. Zero-config defaults. client.marketInfos() returns every scalar field by default — REST-like. Narrow the payload with Selection(...) only when you care.
  2. Typed responses out of the box. Every response is a Pydantic v2 model — .marketId, .status, full IDE autocomplete, and .model_dump() if you need a dict.
  3. Typed operations too. Method names (client.marketInfos, client.confirmOrder) and params= keys autocomplete in VS Code / Pyright / mypy. Typos fail type-check before you run your code.
  4. One set of credentials, three clients. The User singleton caches the JWT, so STX, AsyncSTX, and STXWebSocket share auth in a single process.
  5. Auto-refreshed tokens. JWTs expire after 60 minutes; the SDK refreshes at 59 so you don’t see STXTokenExpiredException in steady-state code.
  6. Typed exceptions. STXAuthException, STXRateLimitException, STXValidationException, and friends — not a single catch-all APIError.
  7. Schema pinned to your SDK version. The GraphQL schema ships with the package; upgrade the SDK to pick up new fields. Opt into always-latest mode when you need bleeding-edge fields.

Compatibility

Supported
Python3.11, 3.12, 3.13 (3.9, 3.10 best-effort)
OSLinux, macOS, Windows
Async runtimeasyncio (native); trio/anyio via compat layer (not tested)
Working end-to-end examples live in stxapp/stx-python-demo:
  • quickstart.py — minimum viable first call
  • list_markets.py — comparison of narrow Selection vs. default-all-fields payload sizes
  • place_order.py — order placement with dry-run mode
  • websocket_feed.py — subscribe to live market updates over Phoenix

Support