Skip to content

Python SDK

stx-python is the Python SDK for the STX exchange. Read markets, place and cancel orders, follow your account, and stream the WebSocket channels, with every request signed by your API key and every response a typed model. Response fields are described in the API reference.

pip install stx-python
from stx import STX
# Reads your API key and exchange from STX_* environment variables or ~/.stx/credentials.
with STX() as client:
me = client.me()
page = client.markets(status="open", limit=5)
print(me.user_id, [m.symbol for m in page])

Authentication shows how to give the client your API key, and Environments lists the exchanges and where to get a key.

There are three clients:

  • STX: blocking, one method per API call.
  • AsyncSTX: the same methods for asyncio. See Async.
  • STXWebSocket: the channels you join, over one signed socket that keeps itself alive and reconnects. See WebSockets.

Amounts come back as decimal strings, exactly as the API sends them: dollars with at least four decimals (order.price == "0.5600") and contract counts with at least two ("2.00"). Orders take strings too: place_order(market_id, "buy", "limit", price="0.56", quantity="2"). Passing a float raises TypeError before anything is sent. Use decimal.Decimal for arithmetic:

from decimal import Decimal
from stx import STX
with STX() as client:
for market in client.markets(status="open", limit=3):
spread = None
if market.bids and market.offers:
spread = Decimal(market.offers[0].price) - Decimal(market.bids[0].price)
print(market.symbol, "pays", market.max_price, "spread", spread)

Prices are the same on every channel: the SDK converts the channels that send cents on the wire to dollar strings. Values that are not money stay numbers: percentages, counts, loyalty points, fee factors and timestamps.

Released under the MIT license.

v1.5.9Changelogllms.txtllms-full.txt