Documentation Index
Fetch the complete documentation index at: https://docs.sportsxapp.com/llms.txt
Use this file to discover all available pages before exploring further.
STXWebSocket is the async-native WebSocket client. One TCP connection, many Phoenix channels, reconnect + heartbeat + resubscribe handled for you.
Quick start
What you get for free
Reconnect
Connection drops trigger exponential-backoff reconnect. Your handlers keep firing on the new socket — no code change needed.
Resubscribe
Every
join() is cached. After a reconnect the SDK replays all phx_join frames before dispatching any user messages.Heartbeat
Phoenix heartbeat frames every 30 s. Servers consider a socket stale without them and drop the connection.
Clean close
async with ws: (or await ws.close()) sends phx_leave for each active subscription before closing the socket.Channels
Import fromstx.enums.Channels:
| Channel | Scope | What it pushes |
|---|---|---|
MARKETS | broadcast | Market-level price and status updates, with optional server-side filtering |
TRADES | per-user | Your trade fills |
ORDERS | per-user | Your order status changes |
POSITIONS | per-user | Your position updates |
SETTLEMENTS | per-user | Settlement events for your account |
PORTFOLIO | per-user | Balance and PnL changes |
USER_INFO | per-user | Account-level updates |
Channels enum — Channels.PORTFOLIO becomes the wire topic portfolio:<your-uid> automatically.
Markets
Broadcast — anyone with a valid JWT can join:market_updated— price, status, or order-book change for an existing marketmarket_created— a new market was listed
Filter at join time
The server supports three filter axes viajoin_params. All three are optional and combinable.
| Field | Effect |
|---|---|
fields | Whitelist of fields to include in each frame. market_id, timestamp, unix_timestamp are always sent. Omit or empty list = all fields. |
rule_filters | Whitelist of rule names (e.g. spread, home_winner). Omit, empty, or null = all markets. |
message_types | Subset of ["market_updated", "market_created"]. Omit = both. |
phx_reply frame) echoes the effective config:
Change filters mid-stream
You don’t have to re-join to swap filters. Usews.push() to send a control message on an already-joined channel:
| Event | Payload | Effect |
|---|---|---|
select_fields | {"fields": [...]} | Replace the field selection |
select_rule_filters | {"rule_filters": [...] or null} | Replace or disable rule filtering |
select_message_types | {"message_types": [...]} | Replace message-type filter |
phx_reply echoing the new config — handle it in your on_message like any other frame.
Orders
Per-user — receives your order-status transitions in real time. Replaces pollingclient.orders(). The Channels.ORDERS enum auto-scopes to your uid:
Portfolio
Per-user — balance updates and PnL tick updates.Per-user channels (
ORDERS, PORTFOLIO, TRADES, …) rely on the JWT to identify you. The WS client reuses the same User singleton as STX / AsyncSTX — call any authenticated sync or async method once before opening the socket, or pass email/password to STXWebSocket directly.For admin tools that need to watch another user’s channel, pass a raw string topic ("portfolio:other-uid") instead of the enum — the auto-scoping is skipped.Message shape
Every handler receives aChannelMessage:
phx_reply, phx_error) — filter for them in your handler if you don’t want to see them:
Multiple subscriptions
One socket, many channels:join() gets its own handler. The SDK routes inbound frames to the right one by channel topic.
Reconnect behaviour
The reconnect loop follows the SDK’s standardRetryPolicy — exponential backoff with jitter, up to max_attempts. Override it:
- Drops the old socket.
- Backs off (up to
retry.max_attempts). - Opens a new socket to the same host.
- Replays every
phx_joinit sent before the drop. - Resumes dispatching user frames.
Custom heartbeat interval
Default is 30 s, matching the server’s idle timeout. For tests you might want faster:Close and leave
Handler exceptions
An exception in a handler won’t kill the reader loop — it’s caught, logged atWARNING, and the next frame proceeds. This means a buggy handler can silently swallow messages. Instrument your handlers if that matters to you.
Example: market-maker skeleton
Next
Async HTTP
Pair
STXWebSocket with AsyncSTX for event-driven bots.Errors & retries
Reconnect policy and how it interacts with the retry system.