Skip to content

AsyncSTX

Describes stx-python 0.10.1, the current release.

Async client for the STX exchange.

Configuration comes from the arguments, then environment variables, then a profile in ~/.stx/credentials:

async with AsyncSTX() as client:
me = await client.me()
page = await client.markets(status="open", limit=10)
Parameter Description
region with env, picks a known host, e.g. region="us", env="demo".
env the environment within region, e.g. "demo" or "production".
host a hostname or URL, overriding region/env.
key_id the API key id.
private_key the key’s Ed25519 private key (PEM text or a path to a PEM file).
signer instead of private_key, a callable bytes -> bytes returning the raw Ed25519 signature (for keys in an HSM or KMS).
profile section of ~/.stx/credentials to read.
verify_tls set False only for a local server.
retry a stx.RetryPolicy; stx.NO_RETRY disables retries.
timeout seconds per HTTP request.
transport an httpx.AsyncBaseTransport, for tests.
access_token instead of an API key, an OAuth access token for a member (sent as Authorization: Bearer, no refresh). For tokens that renew themselves use stx.oauth member clients.
auth instead of an API key, any auth provider (stx.AuthProvider), such as the member and app adapters in stx.oauth.
on_response called with a stx.ResponseEvent after every HTTP attempt, for logging. Exceptions it raises are ignored.
Attribute Type Description
credentials Optional[ApiKeyCredentials]
auth Optional[AuthProvider]
host str The exchange’s host name, e.g. demo.stxapp.io.
accept_terms(device_id: str, *, accept_terms: bool = True, accept_privacy: bool = True, accept_house_rules: Optional[bool] = None) -> str

POST /api/v1/tnc/accept: accept the current terms for your own account, with your own API key. Returns the server’s message.

An app cannot accept the terms for a member: called with a member’s OAuth token, the exchange answers 403 terms_not_delegable (STXForbiddenException). The member accepts on an STX page; see STXTermsRequiredException.terms_url.

Parameter Type Description
device_id str
accept_terms bool
accept_privacy bool
accept_house_rules Optional[bool]
account_market_stats(*, market_ids: StrList = None, event_ids: StrList = None, exclude_zero_settlements: Optional[bool] = None, from_time: Optional[int] = None, to_time: Optional[int] = None, sports: StrList = None, competitions: StrList = None, limit: Optional[int] = None, cursor: Optional[str] = None, unsettled_only: Optional[bool] = None) -> Page[models.MarketStat]

GET /api/v1/account/market_stats: your exposure and P&L per market.

Not the public market_stats channel, which carries prices. unsettled_only=True keeps markets not yet settled.

Parameter Type Description
market_ids StrList
event_ids StrList
exclude_zero_settlements Optional[bool]
from_time Optional[int]
to_time Optional[int]
sports StrList
competitions StrList
limit Optional[int]
cursor Optional[str]
unsettled_only Optional[bool]
adjustments(*, limit: Optional[int] = None, cursor: Optional[str] = None) -> Page[models.PaymentTransaction]

GET /api/v1/portfolio/adjustments: manual balance adjustments.

Parameter Type Description
limit Optional[int]
cursor Optional[str]
balance() -> models.Balance

GET /api/v1/account/balance: balance, liabilities and fee schedule.

The same object the balances channel pushes.

cancel_all_orders() -> List[models.Cancellation]

DELETE /api/v1/orders/all: cancel everything resting on the account.

cancel_order(order_id: str) -> models.Cancellation

DELETE /api/v1/orders/{order_id}: request a cancel.

A cancel is a request: a fill already in flight can still land.

Parameter Type Description
order_id str
cancel_orders(order_ids: Sequence[str]) -> List[models.Cancellation]

DELETE /api/v1/orders/batched: cancel the named orders.

Parameter Type Description
order_ids Sequence[str]
capabilities(*, refresh: bool = False, probe_channels: bool = True) -> Capabilities

What this exchange offers, as a stx.Capabilities.

Probes read-only (discovery documents, GET routes, one channel join left at once) and caches the answer on the client; pass refresh=True to ask again. probe_channels=False skips the socket (combos is then unknown). How each feature is decided is documented in stx._capabilities:

caps = await client.capabilities()
caps.available("combos") # True when the exchange has combos
caps.to_dict() # {"oauth": True, ...}
Parameter Type Description
refresh bool
probe_channels bool
create_markets(event_id: str, markets: Sequence[MarketLike], *, dry_run: bool = False, validate: bool = False) -> List[CreateMarketResult]

POST /api/v1/markets: create markets on a scheduled event.

Up to MAX_MARKETS_PER_REQUEST (25) per call, each a stx.PlayerStatLine or a dict of wire fields:

results = await app.create_markets(event_id, [
PlayerStatLine(player_id="3895074", stat=Stats.Hockey.GOAL_SO, line=3.5),
], dry_run=True)

Needs an OAuth app token with markets.write, which STX grants, sent from an address on the app’s IP allow-list (else STXIpNotAllowedException). Returns one stx.CreateMarketResult per market, in the order given: created or exists (with market_id), valid with dry_run, or rejected with a reason. A rejected market is a result, not an error, and resending is safe: a market already listed comes back exists.

dry_run runs every check on the exchange and creates nothing. validate checks each player stat line against event_players first (so the token also needs events) and returns failures as rejected without sending them.

Raises STXNotAvailableError (markets.create) on an exchange that does not offer it, STXForbiddenException without markets.write, STXNotFoundException for an unknown event and STXRejectedException when the event is not open.

Parameter Type Description
event_id str
markets Sequence[MarketLike]
dry_run bool
validate bool
deposits(*, limit: Optional[int] = None, cursor: Optional[str] = None) -> Page[models.PaymentTransaction]

GET /api/v1/portfolio/deposits.

Parameter Type Description
limit Optional[int]
cursor Optional[str]
event_players(event_id: str) -> EventPlayers

GET /api/v1/events/{event_id}/players: the event’s rosters and the stats a market on it can use.

teams is empty until the rosters are published. Needs an API key, or an OAuth app token with events. Raises STXNotFoundException for an unknown event and STXNotAvailableError (event_players) on an exchange without the route.

Parameter Type Description
event_id str
events(*, event_ids: StrList = None, sports: StrList = None, competitions: StrList = None, event_types: StrList = None, title: Optional[str] = None, status: Optional[str] = None, promoted: Optional[bool] = None, sort_by: Optional[str] = None, sort_direction: Optional[str] = None, limit: Optional[int] = None, cursor: Optional[str] = None) -> Page[models.Event]

GET /api/v1/events: one page of events.

status is one of scheduled, in_progress, completed, cancelled. sort_by is "start_time".

Parameter Type Description
event_ids StrList
sports StrList
competitions StrList
event_types StrList
title Optional[str]
status Optional[str]
promoted Optional[bool]
sort_by Optional[str]
sort_direction Optional[str]
limit Optional[int]
cursor Optional[str]
fees(*, limit: Optional[int] = None, cursor: Optional[str] = None) -> Page[models.FeeTransaction]

GET /api/v1/portfolio/fees: fee and fee-refund entries.

Parameter Type Description
limit Optional[int]
cursor Optional[str]
fills(*, market_ids: StrList = None, order_ids: StrList = None, status: Optional[str] = None, limit: Optional[int] = None, cursor: Optional[str] = None) -> Page[models.Fill]

GET /api/v1/fills: one page of your executions.

order_ids narrows to the fills of those orders. status is one of created, open, settled, cancelled.

Parameter Type Description
market_ids StrList
order_ids StrList
status Optional[str]
limit Optional[int]
cursor Optional[str]
iter_account_market_stats(*, market_ids: StrList = None, event_ids: StrList = None, exclude_zero_settlements: Optional[bool] = None, from_time: Optional[int] = None, to_time: Optional[int] = None, sports: StrList = None, competitions: StrList = None, limit: Optional[int] = None, unsettled_only: Optional[bool] = None) -> AsyncIterator[models.MarketStat]

Every per-market stat row, following the cursor.

Parameter Type Description
market_ids StrList
event_ids StrList
exclude_zero_settlements Optional[bool]
from_time Optional[int]
to_time Optional[int]
sports StrList
competitions StrList
limit Optional[int]
unsettled_only Optional[bool]
iter_adjustments(*, limit: Optional[int] = None) -> AsyncIterator[models.PaymentTransaction]

Every adjustment, following the cursor.

Parameter Type Description
limit Optional[int]
iter_deposits(*, limit: Optional[int] = None) -> AsyncIterator[models.PaymentTransaction]

Every deposit, following the cursor.

Parameter Type Description
limit Optional[int]
iter_events(*, event_ids: StrList = None, sports: StrList = None, competitions: StrList = None, event_types: StrList = None, title: Optional[str] = None, status: Optional[str] = None, promoted: Optional[bool] = None, sort_by: Optional[str] = None, sort_direction: Optional[str] = None, limit: Optional[int] = None) -> AsyncIterator[models.Event]

Every event matching the filters, following the cursor.

Parameter Type Description
event_ids StrList
sports StrList
competitions StrList
event_types StrList
title Optional[str]
status Optional[str]
promoted Optional[bool]
sort_by Optional[str]
sort_direction Optional[str]
limit Optional[int]
iter_fees(*, limit: Optional[int] = None) -> AsyncIterator[models.FeeTransaction]

Every fee entry, following the cursor.

Parameter Type Description
limit Optional[int]
iter_fills(*, market_ids: StrList = None, order_ids: StrList = None, status: Optional[str] = None, limit: Optional[int] = None) -> AsyncIterator[models.Fill]

Every fill matching the filters, following the cursor.

Parameter Type Description
market_ids StrList
order_ids StrList
status Optional[str]
limit Optional[int]
iter_loyalty(*, limit: Optional[int] = None) -> AsyncIterator[models.Transaction]

Every loyalty entry, following the cursor.

Parameter Type Description
limit Optional[int]
iter_markets(*, market_ids: StrList = None, event_ids: StrList = None, status: StrList = None, trading: Optional[bool] = None, sports: StrList = None, competitions: StrList = None, sort_by: Optional[str] = None, sort_direction: Optional[str] = None, limit: Optional[int] = None) -> AsyncIterator[models.Market]

Every market matching the filters, following the cursor.

Parameter Type Description
market_ids StrList
event_ids StrList
status StrList
trading Optional[bool]
sports StrList
competitions StrList
sort_by Optional[str]
sort_direction Optional[str]
limit Optional[int]
iter_orders(*, order_ids: StrList = None, client_order_ids: StrList = None, market_ids: StrList = None, status: StrList = None, limit: Optional[int] = None) -> AsyncIterator[models.Order]

Every order matching the filters, following the cursor.

Parameter Type Description
order_ids StrList
client_order_ids StrList
market_ids StrList
status StrList
limit Optional[int]
iter_settlements(*, market_ids: StrList = None, type: Optional[str] = None, limit: Optional[int] = None) -> AsyncIterator[models.Settlement]

Every settlement, following the cursor.

Parameter Type Description
market_ids StrList
type Optional[str]
limit Optional[int]
iter_withdrawals(*, limit: Optional[int] = None) -> AsyncIterator[models.PaymentTransaction]

Every withdrawal, following the cursor.

Parameter Type Description
limit Optional[int]
leaderboard(*, period: Optional[str] = None, category: Optional[str] = None, metric: Optional[str] = None, limit: Optional[int] = None) -> models.Leaderboard

GET /api/v1/leaderboard: the top members for one board.

period is daily, weekly (default), monthly, yearly or all; metric one of volume, profit, predictions, markets, win_rate, biggest_win, return, streak. STXNotAvailableError (leaderboard) where the exchange has none.

Parameter Type Description
period Optional[str]
category Optional[str]
metric Optional[str]
limit Optional[int]
leaderboard_me(*, period: Optional[str] = None, category: Optional[str] = None) -> models.LeaderboardStanding

GET /api/v1/leaderboard/me: your rank on every shown board.

Parameter Type Description
period Optional[str]
category Optional[str]
loyalty(*, limit: Optional[int] = None, cursor: Optional[str] = None) -> Page[models.Transaction]

GET /api/v1/portfolio/loyalty: loyalty entries.

Parameter Type Description
limit Optional[int]
cursor Optional[str]
market(market_id: str) -> models.Market

One market by id. Raises STXNotFoundException if there is none.

Parameter Type Description
market_id str
market_types() -> Dict[str, MarketType]

GET /api/v1/types: the market types, keyed by rule.

A type with partner_create True can be created with create_markets, and lists its fields and, per event type, the stats on offer. It changes only when STX adds a rule or a stat, so read it once and keep it. Needs an API key, or an OAuth app token with events. STXNotAvailableError (market_types) on an exchange without it.

markets(*, market_ids: StrList = None, event_ids: StrList = None, status: StrList = None, trading: Optional[bool] = None, sports: StrList = None, competitions: StrList = None, sort_by: Optional[str] = None, sort_direction: Optional[str] = None, limit: Optional[int] = None, cursor: Optional[str] = None) -> Page[models.Market]

GET /api/v1/markets: one page of markets.

Filters combine with AND; list filters match any value. status takes one status or a list (["pre_open", "open"]). sort_by is "event_start" with sort_direction "asc" or "desc". limit defaults to 100, maximum 200.

Parameter Type Description
market_ids StrList
event_ids StrList
status StrList
trading Optional[bool]
sports StrList
competitions StrList
sort_by Optional[str]
sort_direction Optional[str]
limit Optional[int]
cursor Optional[str]
me() -> models.Me

GET /api/v1/me: who this key belongs to.

Returns the user_id the account channels are keyed by, the account_id, and the key’s scope (read_only or read_write).

order(order_id: str) -> models.Order

GET /api/v1/orders/{order_id}: one of your orders.

Parameter Type Description
order_id str
orders(*, order_ids: StrList = None, client_order_ids: StrList = None, market_ids: StrList = None, status: StrList = None, limit: Optional[int] = None, cursor: Optional[str] = None) -> Page[models.Order]

GET /api/v1/orders: one page of your orders, newest first.

status takes one status or a list, e.g. ["open", "delayed"].

Parameter Type Description
order_ids StrList
client_order_ids StrList
market_ids StrList
status StrList
limit Optional[int]
cursor Optional[str]
place_order(market_id: str, action: str, order_type: str, *, price: Optional[Amount] = None, quantity: Amount, client_order_id: Optional[str] = None, expiration: Optional[str] = None, expiration_time: Optional[int] = None, cancel_on_disconnect: Optional[bool] = None, device_id: Optional[str] = None, fill_mode: Optional[str] = None) -> models.Order

POST /api/v1/orders: place one order.

action is "buy" or "sell"; order_type is "limit" or "market". price (dollars, required for a limit order) and quantity (contracts) are decimal strings, e.g. price="0.58", quantity="100". Floats are refused client-side.

expiration is "good_till_start" or "good_till_time"; the latter needs expiration_time in Unix microseconds. cancel_on_disconnect=True opts this order into cancel-on- disconnect, which also needs the orders channel joined with it armed (see stx.STXWebSocket.orders).

fill_mode (limit orders only) is "normal" (the default), "post_only" or "fill_or_kill":

  • "post_only" only ever rests on the book as a maker. When it would match on arrival, the exchange does not place it and this raises STXPostOnlyWouldMatchException.
  • "fill_or_kill" fills in full or not at all. The order comes back accepted (or delayed in play); follow it on the orders channel or with order to see it filled or cancelled.

The exchange decides whether it takes either mode. Where a mode is not enabled it rejects the order and this raises STXNotAvailableError (feature "orders.post_only" or "orders.fill_or_kill"). An exchange on a release from before fill modes places the order as a normal limit order. A combination market raises STXFillModeNotAllowedException.

The exchange validates the order: a bad price step or a fractional quantity raises STXValidationException (400) or STXRejectedException (422) with the API’s message.

A POST is never retried after a 5xx or a dropped connection; pass client_order_id so you can look the order up if that happens.

Parameter Type Description
market_id str
action str
order_type str
price Optional[Amount]
quantity Amount
client_order_id Optional[str]
expiration Optional[str]
expiration_time Optional[int]
cancel_on_disconnect Optional[bool]
device_id Optional[str]
fill_mode Optional[str]
place_orders(orders: Sequence[Mapping[str, Any]]) -> List[BatchOrderResult]

POST /api/v1/orders/batched: place several orders in one call.

Each order is a dict with the same fields as place_order:

await client.place_orders([
{"market_id": m, "action": "buy", "order_type": "limit",
"price": "0.01", "quantity": "1"},
{"market_id": m, "action": "buy", "order_type": "limit",
"price": "0.02", "quantity": "1"},
])

Returns one stx.BatchOrderResult per order, in order; a rejected order has errors instead of order and does not stop the others. A post_only order that would have matched comes back as its order, cancelled with cancellation_reason auto_matching.

When the exchange refuses the whole batch because a fill mode is not enabled there, this raises STXNotAvailableError as place_order does.

Parameter Type Description
orders Sequence[Mapping[str, Any]]
positions(*, market_ids: StrList = None) -> List[models.Position]

GET /api/v1/positions: your open positions.

The same objects the positions channel sends on join. position is positive when long, negative when short.

Parameter Type Description
market_ids StrList
settlements(*, market_ids: StrList = None, type: Optional[str] = None, limit: Optional[int] = None, cursor: Optional[str] = None) -> Page[models.Settlement]

GET /api/v1/portfolio/settlements: settlements on your account.

type is one of closed_short, closed_long, expired_short, expired_long.

Parameter Type Description
market_ids StrList
type Optional[str]
limit Optional[int]
cursor Optional[str]
stats_for(event_id: str) -> List[str]

The stat keys event_id accepts for new markets, e.g. ["POINTS"].

Parameter Type Description
event_id str
update_profile(*, handle: Optional[str] = None, avatar: Optional[Mapping[str, Any]] = None, leaderboard_opt_in: Optional[bool] = None) -> models.Me

PATCH /api/v1/me/profile: change your public handle, avatar or leaderboard opt-in. Returns the same object as me.

Parameter Type Description
handle Optional[str]
avatar Optional[Mapping[str, Any]]
leaderboard_opt_in Optional[bool]
user_id() -> str

The user id from me, fetched once and cached.

If me is not permitted (a member token without profile.read), the id comes from balance, which carries the same user_id.

websocket(**kwargs: Any) -> STXWebSocket

An stx.STXWebSocket using this client’s host and key.

Account channels need your user id; the socket fetches it through this client’s me on first use.

Parameter Type Description
kwargs Any
withdrawals(*, limit: Optional[int] = None, cursor: Optional[str] = None) -> Page[models.PaymentTransaction]

GET /api/v1/portfolio/withdrawals.

Parameter Type Description
limit Optional[int]
cursor Optional[str]

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