You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- Use more permissive Iterable type in API calls where any iterable
works. Previously a list was required.
- Add temporary fix for frankie567/httpx-ws#107 until
frankie567/httpx-ws#129 is merged.
- Add docs on using anyio BlockingPortals to use the SDK in a sync
context.
- Fix broken part of streamer proxy test
Since v12.0.0, the SDK is async-only. However, that doesn't mean there is no way make sync requests as before--you'll just have to jump through a few hoops to do so.
5
+
6
+
Blocking portals
7
+
----------------
8
+
9
+
``anyio`` provides a useful tool for stringing together async calls in a sync context called a blocking portal, which runs an event loop in a dedicated thread:
10
+
11
+
.. code-block:: python
12
+
13
+
from functools import partial
14
+
from anyio.from_thread import start_blocking_portal
15
+
from tastytrade import Account, Session
16
+
17
+
sesh = Session("secret", "refresh")
18
+
with start_blocking_portal() as portal:
19
+
acc = portal.call(Account.get, sesh, "5WX01234")
20
+
print(
21
+
portal.call(
22
+
# we use partial since anyio functions don't support keyword arguments
This allows you to weave together sync and async calls seamlessly in a sync context. It even works with streamers, which wasn't possible before:
28
+
29
+
.. code-block:: python
30
+
31
+
from tastytrade import DXLinkStreamer
32
+
from tastytrade.dxfeed import Quote
33
+
34
+
with start_blocking_portal() as portal:
35
+
streamer = DXLinkStreamer(sesh)
36
+
with portal.wrap_async_context_manager(streamer.__asynccontextmanager__()):
37
+
portal.call(streamer.subscribe, Quote, ["SPY"])
38
+
print(portal.call(streamer.get_event, Quote))
39
+
40
+
You can read more about this functionality in the `anyio docs <https://anyio.readthedocs.io/en/stable/threads.html#running-code-from-threads-using-blocking-portals>`_.
0 commit comments