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)Constructor
Section titled “Constructor”| 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. |
Attributes
Section titled “Attributes”| Attribute | Type | Description |
|---|---|---|
credentials |
Optional[ApiKeyCredentials] |
Methods
Section titled “Methods”accept_terms()
Section titled “accept_terms()”accept_terms(device_id: str, *, accept_terms: bool = True, accept_privacy: bool = True, accept_house_rules: Optional[bool] = None) -> strPOST /api/v1/tnc/accept: accept the current terms. Returns the
server’s message.
| Parameter | Type | Description |
|---|---|---|
device_id |
str |
|
accept_terms |
bool |
|
accept_privacy |
bool |
|
accept_house_rules |
Optional[bool] |
account_market_stats()
Section titled “account_market_stats()”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) -> 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.
| 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] |
adjustments()
Section titled “adjustments()”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()
Section titled “balance()”balance() -> models.BalanceGET /api/v1/account/balance: balance, liabilities and fee schedule.
The same object the balances channel pushes.
cancel_all_orders()
Section titled “cancel_all_orders()”cancel_all_orders() -> List[models.Cancellation]DELETE /api/v1/orders/all: cancel everything resting on the account.
cancel_order()
Section titled “cancel_order()”cancel_order(order_id: str) -> models.CancellationDELETE /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()
Section titled “cancel_orders()”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] |
deposits()
Section titled “deposits()”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] |
events()
Section titled “events()”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()
Section titled “fees()”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()
Section titled “fills()”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()
Section titled “iter_account_market_stats()”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) -> 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] |
iter_adjustments()
Section titled “iter_adjustments()”iter_adjustments(*, limit: Optional[int] = None) -> AsyncIterator[models.PaymentTransaction]Every adjustment, following the cursor.
| Parameter | Type | Description |
|---|---|---|
limit |
Optional[int] |
iter_deposits()
Section titled “iter_deposits()”iter_deposits(*, limit: Optional[int] = None) -> AsyncIterator[models.PaymentTransaction]Every deposit, following the cursor.
| Parameter | Type | Description |
|---|---|---|
limit |
Optional[int] |
iter_events()
Section titled “iter_events()”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()
Section titled “iter_fees()”iter_fees(*, limit: Optional[int] = None) -> AsyncIterator[models.FeeTransaction]Every fee entry, following the cursor.
| Parameter | Type | Description |
|---|---|---|
limit |
Optional[int] |
iter_fills()
Section titled “iter_fills()”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()
Section titled “iter_loyalty()”iter_loyalty(*, limit: Optional[int] = None) -> AsyncIterator[models.Transaction]Every loyalty entry, following the cursor.
| Parameter | Type | Description |
|---|---|---|
limit |
Optional[int] |
iter_markets()
Section titled “iter_markets()”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()
Section titled “iter_orders()”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()
Section titled “iter_settlements()”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()
Section titled “iter_withdrawals()”iter_withdrawals(*, limit: Optional[int] = None) -> AsyncIterator[models.PaymentTransaction]Every withdrawal, following the cursor.
| Parameter | Type | Description |
|---|---|---|
limit |
Optional[int] |
loyalty()
Section titled “loyalty()”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()
Section titled “market()”market(market_id: str) -> models.MarketOne market by id. Raises STXNotFoundException if there is none.
| Parameter | Type | Description |
|---|---|---|
market_id |
str |
markets()
Section titled “markets()”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.MeGET /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()
Section titled “order()”order(order_id: str) -> models.OrderGET /api/v1/orders/{order_id}: one of your orders.
| Parameter | Type | Description |
|---|---|---|
order_id |
str |
orders()
Section titled “orders()”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()
Section titled “place_order()”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) -> models.OrderPOST /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.56", quantity="2". 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).
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] |
place_orders()
Section titled “place_orders()”place_orders(orders: Sequence[Mapping[str, *, Any]], geo_location: Optional[str] = None) -> 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.
| Parameter | Type | Description |
|---|---|---|
orders |
Sequence[Mapping[str, Any]] |
|
geo_location |
Optional[str] |
positions()
Section titled “positions()”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()
Section titled “settlements()”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] |
user_id()
Section titled “user_id()”user_id() -> strThe user id from me, fetched once and cached.
websocket()
Section titled “websocket()”websocket(**kwargs: Any) -> STXWebSocketAn 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()
Section titled “withdrawals()”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] |

