Skip to content

Async

Describes stx-python 0.10.1, the current release.

AsyncSTX is the SDK’s implementation; STX runs it on a private event loop. Use AsyncSTX when you keep many requests in flight or combine client calls with streams.

import asyncio
from stx import AsyncSTX
async def main():
async with AsyncSTX() as client:
me, markets, orders, fills = await asyncio.gather(
client.me(),
client.markets(status="open", limit=5),
client.orders(limit=5),
client.fills(limit=5),
)
print(me.user_id, len(markets), len(orders), len(fills))
asyncio.run(main())

Sample output:

e6528824-b4e0-4ff8-bd70-36e5904738d1 2 2 2

One AsyncSTX holds one HTTP connection pool; share it across tasks rather than creating one per request. Close it with async with or await client.close().

import asyncio
from stx import AsyncSTX
async def main():
async with AsyncSTX() as client:
count = 0
async for market in client.iter_markets(status="open", limit=200):
count += 1
if count >= 300:
break
print("saw", count, "markets")
asyncio.run(main())
import asyncio
from stx import AsyncSTX
async def main():
async with AsyncSTX() as client:
ids = [m.market_id for m in await client.markets(status="open", limit=3)]
async with client.websocket() as ws:
books = {}
def on_book(msg):
books[msg.payload["market_id"]] = msg.payload # replace, never merge
await ws.orderbook(ids, on_message=on_book)
fills = await ws.fills()
await fills.wait_snapshot()
await asyncio.sleep(5)
print("books held:", len(books))
asyncio.run(main())

STX has every AsyncSTX client method without await, and works inside a program or notebook that already runs an event loop. client.async_client is the underlying AsyncSTX, bound to STX’s own loop thread. WebSockets are async only.

from stx import STX
with STX() as client:
for order in client.iter_orders(limit=50):
print(order.id, order.status)
break

Sample output:

4702e9b6-211a-4805-a605-0eb0817ee9b3 open

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