Metadata-Version: 2.4
Name: stx-python
Version: 0.7.1
Summary: Official Python SDK for the STX exchange
Author-email: STX <support@stxapp.io>
License-Expression: MIT
Project-URL: Homepage, https://docs.stxapp.io/sdks/python/
Project-URL: Documentation, https://docs.stxapp.io/sdks/python/
Project-URL: Changelog, https://docs.stxapp.io/changelog/
Project-URL: Examples, https://github.com/stxapp/stx-python-demo
Project-URL: Support, https://docs.stxapp.io/support/
Keywords: stx,exchange,trading,prediction-market,sdk
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Operating System :: OS Independent
Classifier: Intended Audience :: Developers
Classifier: Topic :: Office/Business :: Financial
Classifier: Typing :: Typed
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: httpx<1,>=0.25
Requires-Dist: websockets>=12.0
Requires-Dist: pydantic<3,>=2.0
Requires-Dist: cryptography>=41.0
Provides-Extra: dev
Requires-Dist: pytest>=7; extra == "dev"
Requires-Dist: pytest-asyncio>=0.23; extra == "dev"
Requires-Dist: python-dotenv>=1.0; extra == "dev"
Requires-Dist: ruff==0.16.9; extra == "dev"
Requires-Dist: build>=1.0; extra == "dev"
Requires-Dist: twine>=5.0; extra == "dev"
Requires-Dist: pre-commit>=3.5; extra == "dev"
Requires-Dist: griffe==2.3.0; python_version >= "3.10" and extra == "dev"
Dynamic: license-file

# stx-python

The official Python SDK for the [STX](https://stxapp.io) exchange.

```bash
pip install stx-python
```

Python 3.9 or newer.

## Quickstart

You need an API key for the STX exchange you are building against. [Environments](https://docs.stxapp.io/environments/) lists the exchanges and where to get a key, and [Authentication](https://docs.stxapp.io/sdks/python/authentication/) shows how to give it to the SDK.

```python
from stx import STX

# Reads your API key and exchange from STX_* environment variables or ~/.stx/credentials.
with STX() as client:
    # status "open": markets that have opened for trading (not scheduled, closed or settled).
    # trading=True: only markets accepting orders right now (an open market can be paused).
    # limit: markets per page. Looping over page gives this page; client.iter_markets() walks every page.
    page = client.markets(status="open", trading=True, limit=5)

    for market in page:
        # bids are what buyers will pay, offers what sellers will accept. Both lists run from the
        # highest price to the lowest: the best bid is bids[0], the best offer is offers[-1].
        # Prices are dollars per contract, as strings; a winning contract pays market.max_price.
        bid = market.bids[0].price if market.bids else "-"  # "-" when nobody is bidding
        offer = market.offers[-1].price if market.offers else "-"
        print(f"{market.event_title}: {market.title}  bid {bid}  offer {offer}")
```

Sample output:

```text
Edmonton Oilers at San Jose Sharks: NHL EDM @ SJ  bid 0.5800  offer 0.5900
Edmonton Oilers at San Jose Sharks: C. McDavid 3.5 SOG  bid 0.4900  offer 0.5300
```

A bid of `0.5800` on a market whose winning contract pays `1.0000` means a buyer will pay 58 cents for a contract that pays $1 if the Oilers win.

<details>
<summary>One market from the response (selected fields)</summary>

```json
{
  "market_id": "e00651a3-10cb-4bc1-9e1f-c5ea1796c83b",
  "symbol": "STXNHL-26OCT101600EDMSJ-GAMEEDM",
  "event_title": "Edmonton Oilers at San Jose Sharks",
  "title": "NHL EDM @ SJ",
  "question": "Will the Edmonton Oilers defeat the San Jose Sharks?",
  "status": "open",
  "trading": true,
  "event_start": "2026-10-10T20:00:00.000000Z",
  "max_price": "1.0000",
  "last_traded_price": "0.5800",
  "bids": [
    { "price": "0.5800", "quantity": "210.00" },
    { "price": "0.5700", "quantity": "420.00" },
    { "price": "0.5600", "quantity": "1200.00" }
  ],
  "offers": [
    { "price": "0.6100", "quantity": "900.00" },
    { "price": "0.6000", "quantity": "650.00" },
    { "price": "0.5900", "quantity": "310.00" }
  ]
}
```

Every market is a `stx.models.Market`; `market.model_dump()` gives you the dict. Every field is described in the [API reference](https://docs.stxapp.io/api/rest/).

</details>

For asyncio, `AsyncSTX` has the same methods to `await`, and `client.websocket()` streams the order book, trades and your own orders, fills and balance.

## Documentation

- [Python SDK guide](https://docs.stxapp.io/sdks/python/)
- [API reference](https://docs.stxapp.io/api/rest/)
- [Release notes](https://docs.stxapp.io/changelog/)
- [Support](https://docs.stxapp.io/support/)

MIT license. Use of the STX API and exchange is subject to the STX terms of use and privacy policy: United States ([terms of use](https://stxapp.io/legal/terms-of-use.pdf), [privacy policy](https://stxapp.io/legal/privacy-policy.pdf)), Ontario ([terms of use](https://stxapp.ca/legal/terms-of-use.pdf), [privacy policy](https://stxapp.ca/legal/privacy-policy.pdf)).
