Describes stx-python 0.10.1, the current release.
All amounts are dollar strings and all contract counts are quantity strings, as the API sends them. Every field is described in the API reference.
Balance
Section titled “Balance”balance() calls GET /api/v1/account/balance: cash, what is available, liabilities, lifetime totals and the fee schedule. It is the same object the balances channel pushes.
from stx import STX
with STX() as client: b = client.balance() print("available", b.available_balance, "cash", b.account_balance) print("buy liability", b.buy_order_liability, "sell liability", b.sell_order_liability) print("fees", b.fee_schedule, b.taker_factor, b.maker_factor, "tier", b.loyalty_tier)Sample output:
available 746.8600 cash 804.8600buy liability 34.8000 sell liability 0.0000fees on_trade 0.1 0.0 tier rookieavailable_balance is rounded down to the cent and the liabilities up, so they need not reconcile to the cent; treat each as authoritative.
Positions
Section titled “Positions”positions() calls GET /api/v1/positions and returns your positions (market_ids= narrows them), the same objects the positions channel sends on join.
from stx import STX
with STX() as client: for p in client.positions(): print(p.market_id, "net", p.position, "premium", p.premium, "open risk", p.open_risk)Sample output:
e00651a3-10cb-4bc1-9e1f-c5ea1796c83b net 40.00 premium -23.2000 open risk 23.2000position is positive when long and negative when short. Positions are not marked to market: value them against the order book yourself.
A fill is one of your executions. fills() filters on market_ids, order_ids and status (created, open, settled, cancelled):
from stx import STX
with STX() as client: for f in client.fills(limit=5): print(f.trade_id, f.order_id, f.action, f.filled, "@", f.price, "fee", f.total_fee)
orders = client.orders(status="filled", limit=1) if orders.items: mine = client.fills(order_ids=[orders[0].id]) print("fills for", orders[0].id, [f.filled for f in mine])Sample output, for an account with two fills and no completely filled order:
a7469e3a-b608-483d-b12f-1c1534793274 4702e9b6-211a-4805-a605-0eb0817ee9b3 buy 40.00 @ 0.5800 fee 0.9800fc70fdcf-5e30-49bc-97a5-cbddeab025f5 1dc6ad2a-bd60-42b9-8ac3-7dd28d0eaf2b buy 50.00 @ 0.3600 fee 1.1600total_fee is the all-in fee: the trade fee plus settlement fees so far. unrounded_trade_fee can carry up to nine decimals, so parse with Decimal.
Settlements and history
Section titled “Settlements and history”from stx import STX
with STX() as client: for s in client.settlements(limit=5): print(s.type, s.quantity, s.opening_price, "->", s.closing_price, "pnl", s.realized_pnl)
for name in ("deposits", "withdrawals", "adjustments", "fees", "loyalty"): page = getattr(client, name)(limit=3) print(name, [(t.type, t.amount) for t in page])Sample output:
expired_long 50.00 0.3600 -> 1.0000 pnl 32.0000deposits [('deposit', '1000.0000')]withdrawals [('withdrawal', '250.0000')]adjustments [('adjustment', '25.0000')]fees [('fee', '-0.9800'), ('fee', '-1.1600')]loyalty [('loyalty_points_rollup', '0.0000')]settlements() takes market_ids and type (closed_short, closed_long, expired_short, expired_long). Every history method pages by cursor and has an iter_ twin.
Per-market statistics
Section titled “Per-market statistics”account_market_stats() returns your position, exposure and P&L broken out per market (GET /api/v1/account/market_stats). It is unrelated to the public market_stats channel, which carries prices.
from stx import STX
with STX() as client: for row in client.account_market_stats(exclude_zero_settlements=True, limit=5): print(row.market_id, "position", row.position, "net pnl", row.total_net_pnl)It filters on market_ids, event_ids, sports, competitions, from_time and to_time (Unix microseconds) and exclude_zero_settlements.
Keeping it current
Section titled “Keeping it current”These methods return a snapshot. To stay current, join orders, fills, positions, settlements and balances (or account for all of them) on the socket, and call orders() and the other methods you rely on again after a reconnect. See WebSockets.

