Skip to content

Move to async-only library for version>=12#299

Merged
Graeme22 merged 3 commits intomasterfrom
v12
Feb 5, 2026
Merged

Move to async-only library for version>=12#299
Graeme22 merged 3 commits intomasterfrom
v12

Conversation

@Graeme22
Copy link
Member

@Graeme22 Graeme22 commented Feb 4, 2026

Description

For a long time this library was mostly sync, with the streamers being the exception. PR #168 added async endpoints on top of the existing endpoints, which gave users more flexibility. With this change, I propose that version 12+ be async-only.

There are a few reasons for this. First of all, having both sync and async versions of everything resulted in a ton of code duplication (check out how many lines are removed in this commit!). Second, both streamers are (and always have been) async, meaning that almost all users are already implementing at least some async code, so having the separate sync versions makes less sense. Finally, this change allows us to support Trio and clean up the streamer implementation which was hard to reason about and prone to bugs.

Summary of important changes:

  • httpx-ws library replaces websockets, allowing for Trio support. As a consequence of this, reconnect and disconnect functionality is gone (however, this is almost certainly better handled on the user side anyways).

  • Python 3.10 support is dropped as we're now using ExceptionGroups. This would likely have happened soon anyways as the official support lifecycle only goes through October 2026.

  • All previous sync endpoints are now async. All previous async endpoints have been removed (so instead of having endpoints named Account.a_get for async and Account.get for sync, we have a single endpoint named Account.get, which is async).

  • Session token refreshing is smarter: Instead of making users check and refresh themselves, they will auto-refresh before any request if they're close to expiry. Sessions also have an optional async context manager which can be used to ensure cleanup happens.

  • Streamers now use httpx-ws websockets and structured concurrency, making them much simpler and easier to reason about (which implies a lower chance of bugs in the future). We also get to use the helpful send_json and receive_json functions instead of wrapping everything in json.dumps/json.loads.

  • tastytrade.dxfeed.Quote events now have helpful mid_price and micro_price properties calculated from its bid/ask prices.

  • tastytrade.order.OrderAction has a multiplier property which is -1 when it's a "Sell" leg and 1 when it's a "Buy" leg.

  • Test suite now runs on both asyncio and Trio.

Pre-merge checklist

  • Code formatted correctly (check with make lint)
  • Passing tests locally (check with make test, make sure you have TT_REFRESH, TT_SECRET, and TT_ACCOUNT environment variables set)
  • New tests added (if applicable)

Please note that, in order to pass the tests, you'll need to set up your Tastytrade credentials as repository secrets on your local fork. Read more at CONTRIBUTING.md.

For a long time this library was mostly sync, with the streamers being
the exception. PR #168 added async endpoints on top of the existing
endpoints, which gave users more flexibility. With this change, I
propose that version 12+ be async-only.

There are a few reasons for this. First of all, having both sync and
async versions of everything resulted in a ton of code duplication
(check out how many lines are removed in this commit!). Second, both
streamers are (and always have been) async, meaning that almost all
users are already implementing at least *some* async code, so having the
separate sync versions makes less sense. Finally, this change allows us
to support Trio and clean up the streamer implementation which was hard
to reason about and prone to bugs.

Summary of important changes:

- `httpx-ws` library replaces `websockets`, allowing for Trio support.
  As a consequence of this, reconnect and disconnect functionality is
  gone (however, this is almost certainly better handled on the user
  side anyways).

- Python 3.10 support is dropped as we're now using `ExceptionGroup`s.
  This would likely have happened soon anyways as the official support
  lifecycle only goes through October 2026.

- All previous sync endpoints are now async. All previous async
  endpoints have been removed (so instead of having endpoints named
  `Account.a_get` for async and `Account.get` for sync, we have a single
  endpoint named `Account.get`, which is async).

- Session token refreshing is smarter: Instead of making users check and
  refresh themselves, they will auto-refresh before any request if
  they're close to expiry. Sessions also have an optional async context
  manager which can be used to ensure cleanup happens.

- Streamers now use `httpx-ws` websockets and structured concurrency,
  making them much simpler and easier to reason about (which implies a
  lower chance of bugs in the future). We also get to use the helpful
  `send_json` and `receive_json` functions instead of wrapping
  everything in `json.dumps`/`json.loads`.

- `tastytrade.dxfeed.Quote` events now have helpful `mid_price` and
  `micro_price` properties calculated from its bid/ask prices.

- `tastytrade.order.OrderAction` has a `multiplier` property which is
  `-1` when it's a "Sell" leg and `1` when it's a "Buy" leg.

- Test suite now runs on both asyncio and Trio.
@Graeme22 Graeme22 merged commit 0c6c0b1 into master Feb 5, 2026
4 checks passed
@Graeme22 Graeme22 deleted the v12 branch February 5, 2026 19:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant