Skip to main content
This guide walks through the shortest path from zero to a working GraphQL call against SportsX staging.
Use staging for anything you’re building. env="production" trades with real balances — don’t point a new integration at it until you’ve exercised the code path on staging.

Prerequisites

Walkthrough

1

Install the SDK

pip install stx-python
Verify the install:
python -c "import stx; print(stx.__version__)"
2

Set credentials

The SDK reads credentials from three places, in this precedence: keyword arguments → environment variables → ~/.stx/credentials profile.For a first run, env vars are fastest:
export STX_EMAIL="you@example.com"
export STX_PASSWORD="your-password"
For long-lived setups, see Configuration → Profile files.
3

Make your first call

Create hello_stx.py:
hello_stx.py
from stx import STX, Selection

client = STX(region="ontario", env="staging")

markets = client.marketInfos(
    selections=Selection("marketId", "status", "title"),
)

print(f"Got {len(markets)} markets")
for m in markets[:5]:
    print(f"  {m.marketId}  {m.status:<10}  {m.title}")
Run it:
python hello_stx.py
You should see something like:
Got 217 markets
  mkt_8f3...  open        Who wins Game 4 of the NBA Finals?
  mkt_4a2...  closed      NHL — Leafs vs Rangers, Mar 12
  ...
4

Place your first (dry) order

Orders are authenticated the same way; no extra setup.
from stx import STX, Selection

client = STX(region="ontario", env="staging")

# Find an open market first.
markets = client.marketInfos(
    params={"status": "open"},
    selections=Selection("marketId", "title"),
)
market_id = markets[0].marketId

# Inspect before confirming — nothing hits the exchange here.
preview = client.previewOrder(
    params={
        "marketId": market_id,
        "side": "yes",
        "size": 1,
        "limitPrice": 0.50,
    },
    selections=Selection("estimatedCost", "estimatedFees"),
)
print(preview.estimatedCost, preview.estimatedFees)
To actually place it, swap previewOrder for confirmOrder. See Trading for the full surface.
5

Subscribe to a live feed (optional)

STXWebSocket is async-native. Save as feed.py:
feed.py
import asyncio
from stx import STX, STXWebSocket
from stx.enums import Channels

async def main():
    # The WS client re-uses the JWT cached by a prior STX login.
    STX(region="ontario", env="staging")  # seeds the auth singleton

    async def on_msg(msg):
        print(f"{msg.event}: {msg.payload}")

    async with STXWebSocket(region="ontario", env="staging") as ws:
        await ws.join(Channels.MARKET_INFO, on_message=on_msg)
        await asyncio.sleep(30)   # listen for 30 seconds

asyncio.run(main())
Run it — you’ll see phx_reply (the join ack) followed by live market updates.

What you just did

  • Installed stx-python from PyPI.
  • Logged in with email/password — the SDK cached a JWT and will auto-refresh it at minute 59 of each 60-minute window.
  • Ran a GraphQL query with a narrowed field Selection (small payload).
  • Previewed an order without hitting the order book.
  • (Optionally) joined a Phoenix channel for live market updates.

Next steps

Authentication

2FA, long-lived profiles, and how tokens are refreshed.

Market data

Query orderbooks, event metadata, and historical data.

Trading

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

WebSockets

Subscribe to the full catalog of Phoenix channels.