> ## Documentation Index
> Fetch the complete documentation index at: https://docs.sportsxapp.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Quickstart

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

This guide walks through the shortest path from zero to a working GraphQL call against SportsX staging.

<Note>
  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.
</Note>

## Prerequisites

* Python 3.9 or newer (`python3 --version`)
* An STX account that can log into [app-staging.on.sportsxapp.com](https://app-staging.on.sportsxapp.com)
* `pip` (shipped with Python)

## Walkthrough

<Steps>
  <Step title="Install the SDK">
    ```bash theme={null}
    pip install \
      --index-url https://test.pypi.org/simple/ \
      --extra-index-url https://pypi.org/simple/ \
      "stx-python>=0.5.0a1"
    ```

    `stx-python` is in alpha on TestPyPI. Once stable it'll be `pip install stx-python` from main PyPI. See [Installation](/sdks/python/installation) for the full story.

    Verify:

    ```bash theme={null}
    python -c "import stx; print('OK')"
    ```
  </Step>

  <Step title="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:

    <CodeGroup>
      ```bash macOS / Linux theme={null}
      export STX_EMAIL="you@example.com"
      export STX_PASSWORD="your-password"
      ```

      ```powershell Windows (PowerShell) theme={null}
      $env:STX_EMAIL = "you@example.com"
      $env:STX_PASSWORD = "your-password"
      ```
    </CodeGroup>

    For long-lived setups, see [Configuration → Profile files](/sdks/python/configuration#profile-files).
  </Step>

  <Step title="Make your first call">
    Create `hello_stx.py`:

    ```python hello_stx.py theme={null}
    from stx import STX, Selection

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

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

    print(f"Got {len(markets)} markets")
    for m in markets[:5]:
        print(f"  {m.market_id}  {m.status:<10}  {m.title}")
    ```

    Run it:

    ```bash theme={null}
    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
      ...
    ```
  </Step>

  <Step title="Place a resting order (and cancel it)">
    Orders are authenticated the same way; no extra setup. The example
    below places a deliberately-low LIMIT BUY at 1¢ — it sits in the
    orderbook without filling, so you can exercise the API without
    risking real positions.

    ```python theme={null}
    from stx import STX, Selection

    client = STX(region="ontario", env="staging")
    client.login(params={})

    # Find a tradable market.
    markets = client.markets(
        params={"input": {"status": "OPEN", "trading": "TRUE", "limit": 5}},
        selections=Selection("market_id", "title"),
    )
    market_id = markets[0].market_id

    # Place a resting LIMIT BUY at 1¢ — won't fill at that price.
    result = client.place_order(
        params={
            "user_order": {
                "market_id": market_id,
                "order_type": "LIMIT",
                "action": "BUY",
                "price": 1,
                "quantity": 1,
            }
        },
        selections=Selection(order=Selection("id", "status")),
    )
    print(f"Placed: {result.order.id}  status={result.order.status}")

    # Clean up.
    client.cancel_order(params={"order_id": result.order.id})
    ```

    See [Trading](/sdks/python/trading) for batch ops, odds-orders, and the rest of the surface.
  </Step>

  <Step title="Subscribe to a live feed (optional)">
    `STXWebSocket` is async-native. Save as `feed.py`:

    ```python feed.py theme={null}
    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.MARKETS, 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.
  </Step>
</Steps>

## 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

<CardGroup cols={2}>
  <Card title="Authentication" icon="key" href="/sdks/python/authentication">
    2FA, long-lived profiles, and how tokens are refreshed.
  </Card>

  <Card title="Market data" icon="chart-line" href="/sdks/python/markets">
    Query orderbooks, event metadata, and historical data.
  </Card>

  <Card title="Trading" icon="arrows-rotate" href="/sdks/python/trading">
    Place, cancel, and amend orders; fetch positions and fills.
  </Card>

  <Card title="WebSockets" icon="tower-broadcast" href="/sdks/python/websockets">
    Subscribe to the full catalog of Phoenix channels.
  </Card>
</CardGroup>
