Skip to content

Commit

Permalink
Added asynchronous close method and updated documentation (#211)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexgolec authored Apr 30, 2021
1 parent b4c62d2 commit a80f8af
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
14 changes: 13 additions & 1 deletion examples/async/get_quote.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,14 @@ def make_webdriver():
# Import selenium here because it's slow to import
from selenium import webdriver

driver = webdriver.Chrome()
# Choose your browser of choice by uncommenting the appropriate line. For
# help, see https://selenium-python.readthedocs.io/installation.html#drivers

#driver = webdriver.Chrome()
#driver = webdriver.Firefox()
#driver = webdriver.Safari()
#driver = webdriver.Edge()

atexit.register(lambda: driver.quit())
return driver

Expand All @@ -32,6 +39,11 @@ async def main():
r = await client.get_quote("AAPL")
print(r.json())

# It is highly recommended to close your asynchronous client when you are
# done with it. This step isn't strictly necessary, however not doing so
# will result in warnings from the async HTTP library.
await client.close_async_session()

if __name__ == '__main__':
import asyncio
asyncio.run(main())
3 changes: 3 additions & 0 deletions tda/client/asynchronous.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@

class AsyncClient(BaseClient):

async def close_async_session(self):
await self.session.aclose()

async def _get_request(self, path, params):
self.ensure_updated_refresh_token()

Expand Down
3 changes: 3 additions & 0 deletions tests/client_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1495,3 +1495,6 @@ class AsyncClientTest(_TestClient, unittest.TestCase):
"""
client_class = ResyncProxy(AsyncClient)
magicmock_class = AsyncMagicMock

def test_async_close(self):
self.client.close_async_session()

0 comments on commit a80f8af

Please sign in to comment.