Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion pytr/alarms.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ async def set_alarms(self):
while action_count > 0:
await self.tr.recv()
action_count -= 1
await self.tr.close()
return

def overview(self):
Expand Down Expand Up @@ -151,7 +152,11 @@ def get(self):
except InvalidOperation:
raise ValueError(f"{token} is no valid ISIN or decimal value that could represent an alarm.")

asyncio.run(self.alarms_loop())
async def get_alarms_and_close():
await self.alarms_loop()
await self.tr.close()

asyncio.run(get_alarms_and_close())

self.overview()

Expand Down
7 changes: 7 additions & 0 deletions pytr/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,13 @@ async def _get_ws(self):

return self._ws

async def close(self):
"""Close the websocket connection gracefully."""
if self._ws is not None:
self.log.info("Closing websocket connection...")
await self._ws.close()
self._ws = None

async def _next_subscription_id(self):
async with self._lock:
subscription_id = self._subscription_id_counter
Expand Down
1 change: 1 addition & 0 deletions pytr/details.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ async def details_loop(self):
print(f"unmatched subscription of type '{subscription['type']}':\n{preview(response, num_lines=30)}")

if recv == 6:
await self.tr.close()
return

def print_instrument(self):
Expand Down
2 changes: 2 additions & 0 deletions pytr/portfolio.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,8 @@ async def portfolio_loop(self):
portfolionew.append(pos)
self.portfolio = portfolionew

await self.tr.close()

def _get_sort_func(self):
if self.sort_by_column:
match self.sort_by_column.lower():
Expand Down
2 changes: 2 additions & 0 deletions pytr/timeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ async def tl_loop(self):
else:
self.log.warning(f"unmatched subscription of type '{subscription['type']}':\n{preview(response)}")

await self.tr.close()

async def get_next_timeline_transactions(self, response):
"""
Get timeline transactions and store them in list timeline_transactions
Expand Down
Loading