Skip to content

Python SDK

Describes stx-python 0.10.1, the current release.

This guide describes stx-python 0.8.0.

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. Build an app that STX members connect to, act as your app for market data, and create markets, with OAuth. 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])

Sample output:

e6528824-b4e0-4ff8-bd70-36e5904738d1 ['STXNHL-26OCT101600EDMSJ-GAMEEDM', 'STXNHL-26OCT101600EDMSJ-SOGSJCMCDAVID209555-3.5']

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.

For an app, stx.oauth adds the OAuth clients: connect members and act for them, mint app tokens, and sign members in with STX. See Apps: connect members.

Exchanges do not all offer every feature yet. client.capabilities() says which this one has, and a call that needs a missing feature raises STXNotAvailableError. See What you can do.

Amounts come back as decimal strings, exactly as the API sends them: dollars with at least four decimals (order.price == "0.5800") and contract counts with at least two ("100.00"). Orders take strings too: place_order(market_id, "buy", "limit", price="0.58", quantity="100"). 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:
# Both lists run from the highest price to the lowest: best bid first, best offer last.
spread = Decimal(market.offers[-1].price) - Decimal(market.bids[0].price)
print(market.symbol, "pays", market.max_price, "spread", spread)

Sample output:

STXNHL-26OCT101600EDMSJ-GAMEEDM pays 1.0000 spread 0.0100
STXNHL-26OCT101600EDMSJ-SOGSJCMCDAVID209555-3.5 pays 1.0000 spread 0.0400

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.

STX is operated by XV Exchange, LLC, a Designated Contract Market regulated by the U.S. Commodity Futures Trading Commission (CFTC). Contracts traded on STX are cleared by XV Clearing, LLC, a CFTC-registered Derivatives Clearing Organization. Trading involves substantial risk of loss and may not be appropriate for everyone. Members risk losing the cost to enter any transaction, including fees. Consider whether trading is appropriate for you in light of your experience and financial resources. Nothing on this site is investment advice or a recommendation to trade. Past performance is not indicative of future results.

© 2026 STX. All rights reserved.llms.txtllms-full.txtView as Markdown
Docs version v1.10.5