Skip to content

STXWebSocket

Describes stx-python 0.10.1, the current release.

Async Phoenix-channels client for the documented STX topics.

Build it from an AsyncSTX client, which supplies the host, the key and your user id:

async with AsyncSTX() as client:
async with client.websocket() as ws:
book = await ws.orderbook(["<market-id>"], on_message=print)
orders = await ws.orders()
print(await orders.wait_snapshot())
await ws.run_forever()

or standalone with the same settings arguments as AsyncSTX.

Parameter Description
rest an AsyncSTX to take host, key and user id from.
user_id your user id, if you already have it (skips GET /me).
heartbeat_interval seconds between socket heartbeats. The server closes a socket silent for 60 s.
channel_ping_interval seconds between channel ping frames on every joined topic; None disables them. orders with cancel-on-disconnect pings faster, from the granted timeout.
reconnect reconnect after a drop (default True).
reconnect_policy backoff for reconnects.
on_reconnect called (sync or async) after every successful reconnect and rejoin, and after rejoining a channel the server closed or errored while the socket stayed up: the moment to call orders() and anything else you show again.
on_auth_error called with the exception when the socket gives up because its credentials are dead (an OAuth grant was revoked, stx.oauth.STXGrantRevokedException). The socket is closed by then and ws.error holds the same exception.
access_token standalone only, an OAuth member access token instead of an API key.
join_timeout seconds to wait for a join or push reply.
queue_size messages buffered per channel for async for; the oldest is dropped when full.
Attribute Type Description
url str
error Optional[Exception]
verify_tls bool
channels Dict[str, Channel]
connected bool
account(*, market_ids: Optional[Sequence[str]] = None, on_message: Optional[MessageHandler] = None) -> Channel

account:{user_id}: everything the five channels above carry, on one join. Do not also join a per-type channel (you would get every message twice), and use orders if you need cancel-on-disconnect.

Parameter Type Description
market_ids Optional[Sequence[str]]
on_message Optional[MessageHandler]
account_view(*, market_ids: Optional[Sequence[str]] = None, account_id: Optional[str] = None, on_change: Optional[Callable[[AccountChange], Any]] = None, snapshot_timeout: Optional[float] = 15.0, keep_flat_positions: bool = False, max_fills: int = 1000) -> AccountView

A live copy of your account: balance, open orders, fills and positions.

Joins balances, orders, fills and positions, waits for their join snapshots, then keeps the view current from what the exchange pushes; after a reconnect each snapshot replaces its part. on_change gets a stx.AccountChange per applied message. See stx.AccountView.

Parameter Type Description
market_ids Optional[Sequence[str]]
account_id Optional[str]
on_change Optional[Callable[[AccountChange], Any]]
snapshot_timeout Optional[float]
keep_flat_positions bool
max_fills int
balances(*, account_id: Optional[str] = None, on_message: Optional[MessageHandler] = None) -> Channel

balances:{user_id}: balances on join, then update and payment_update. account_id picks one of your accounts.

Parameter Type Description
account_id Optional[str]
on_message Optional[MessageHandler]
combo_quote(*, on_message: Optional[MessageHandler] = None) -> ComboQuoteChannel

combo_quote:{user_id}: your maker channel for combos.

Returns an stx.combos.ComboQuoteChannel, which receives every request opened after the join (rfq_opened) and sends quote and withdraw_quote. Needs a read_write key.

Raises stx.STXCombosUnavailableException on an environment without combos, and stx.STXComboException with the reason for any other refusal.

Parameter Type Description
on_message Optional[MessageHandler]
connect() -> None

Open the socket. Idempotent.

fills(*, market_ids: Optional[Sequence[str]] = None, on_message: Optional[MessageHandler] = None) -> Channel

fills:{user_id}: all_trades on join, then one trade per execution or status change.

Parameter Type Description
market_ids Optional[Sequence[str]]
on_message Optional[MessageHandler]
join(topic: str, payload: Optional[Dict[str, Any]] = None, *, on_message: Optional[MessageHandler] = None, ping_interval: Any = _UNSET) -> Channel

Join topic with payload and wait for the reply.

Raises STXChannelException with the server’s reason (for example market_ids_required or unauthorized) if the join is refused.

Parameter Type Description
topic str
payload Optional[Dict[str, Any]]
on_message Optional[MessageHandler]
ping_interval Any
market(market_id: str, *, on_message: Optional[MessageHandler] = None) -> Channel

market:<id>: one market in full.

The join reply (channel.reply) is the market’s current state: every market field plus ob, its aggregated book ({"b": [...], "o": [...]}, each level {p, q, l, tc, tl}). Then market_update carries the fields that changed and order_book_update a fresh {"ob": ...} about every 200 ms. The event’s live status rides along (event_brief, detailed_event_brief, event_status). market_id is the market id or symbol. Prices are converted from cents to dollar strings and book levels are written as strings. A resulted or voided market sends one last market_update and the server closes the topic.

Parameter Type Description
market_id str
on_message Optional[MessageHandler]
market_stats(market_ids: Sequence[str], *, range: Optional[str] = None, on_message: Optional[MessageHandler] = None) -> Channel

market_stats: a price series per market. The history is in the join reply (channel.reply["markets"]); market_stats pushes changed buckets (upsert by timestamp_us) and market_stats_snapshot replaces a series.

Parameter Type Description
market_ids Sequence[str]
range Optional[str]
on_message Optional[MessageHandler]
market_updates(watch: Optional[Sequence[str]] = None, *, on_message: Optional[MessageHandler] = None) -> Channel

market_updates: created and updated for the markets you watch. Nothing arrives until you watch something; pass watch= or call channel.watch([...]). Prices are converted from cents to dollar strings here.

Parameter Type Description
watch Optional[Sequence[str]]
on_message Optional[MessageHandler]
markets(*, rule_filters: Optional[Sequence[str]] = None, message_types: Optional[Sequence[str]] = None, on_message: Optional[MessageHandler] = None) -> Channel

markets: market_created and market_updated for every market. Each payload maps market id to a market object; market_updated carries only the changed fields. Prices arrive in cents on the wire and are converted to dollar strings here.

Parameter Type Description
rule_filters Optional[Sequence[str]]
message_types Optional[Sequence[str]]
on_message Optional[MessageHandler]
orderbook(market_ids: Sequence[str], *, on_message: Optional[MessageHandler] = None) -> Channel

orderbook: the aggregated book, one book push per market.

Each push is a full snapshot of that market’s book; replace what you hold rather than merging. market_ids is required.

Parameter Type Description
market_ids Sequence[str]
on_message Optional[MessageHandler]
orders(*, market_ids: Optional[Sequence[str]] = None, cancel_on_disconnect: bool = False, ping_timeout: Optional[int] = None, on_message: Optional[MessageHandler] = None) -> Channel

orders:{user_id}: all_orders on join, then new_open_order.

cancel_on_disconnect=True arms cancel-on-disconnect for orders placed with cancel_on_disconnect=True. ping_timeout is in milliseconds, clamped by the server to 5000 to 20000; the granted value is in channel.reply["ping_timeout"] and the SDK pings at a third of it for as long as the channel is joined.

Parameter Type Description
market_ids Optional[Sequence[str]]
cancel_on_disconnect bool
ping_timeout Optional[int]
on_message Optional[MessageHandler]
positions(*, market_ids: Optional[Sequence[str]] = None, on_message: Optional[MessageHandler] = None) -> Channel

positions:{user_id}: all_positions on join, then updated_positions deltas with only the changed positions.

Parameter Type Description
market_ids Optional[Sequence[str]]
on_message Optional[MessageHandler]
rfq(*, on_message: Optional[MessageHandler] = None) -> RfqChannel

rfq:{user_id}: your player channel for combos.

Returns an stx.combos.RfqChannel, which sends request_quote, cash_out, accept, cancel and snapshot. Needs a read_write key.

Raises stx.STXCombosUnavailableException on an environment without combos, and stx.STXComboException with the reason for any other refusal.

Parameter Type Description
on_message Optional[MessageHandler]
run_forever() -> None

Block until close is called (or reconnects are exhausted).

settlements(*, market_ids: Optional[Sequence[str]] = None, on_message: Optional[MessageHandler] = None) -> Channel

settlements:{user_id}: new_settlements as they are recorded. No snapshot; history is AsyncSTX.settlements().

Parameter Type Description
market_ids Optional[Sequence[str]]
on_message Optional[MessageHandler]
ticker(*, sports: Optional[Sequence[str]] = None, competitions: Optional[Sequence[str]] = None, on_message: Optional[MessageHandler] = None) -> Channel

ticker: a ticker push whenever a market’s price, top of book, volume or open interest moves. No snapshot on join.

Parameter Type Description
sports Optional[Sequence[str]]
competitions Optional[Sequence[str]]
on_message Optional[MessageHandler]
trades(*, market_ids: Optional[Sequence[str]] = None, event_ids: Optional[Sequence[str]] = None, on_message: Optional[MessageHandler] = None) -> Channel

trades: every execution on the exchange, anonymised. action is the taker’s side. Not your fills: see fills.

Parameter Type Description
market_ids Optional[Sequence[str]]
event_ids Optional[Sequence[str]]
on_message Optional[MessageHandler]
user_id() -> str

Your user id, from user_id= or GET /api/v1/me.

user_info(*, on_message: Optional[MessageHandler] = None) -> Channel

user_info:{user_id}: user_updated right after joining, then on every profile change.

Parameter Type Description
on_message Optional[MessageHandler]

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