This repository was archived by the owner on Jun 17, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 552
adds self.run_forever_flag to streams #501
Open
0xfMissingNo
wants to merge
1
commit into
alpacahq:master
Choose a base branch
from
0xfMissingNo:add-run-forever-flag
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -45,6 +45,7 @@ def __init__(self, | |
| 'dailyBars': {}, | ||
| } | ||
| self._name = 'data' | ||
| self._run_forever_flag = False | ||
|
|
||
| async def _connect(self): | ||
| self._ws = await websockets.connect( | ||
|
|
@@ -79,6 +80,7 @@ async def close(self): | |
| await self._ws.close() | ||
| self._ws = None | ||
| self._running = False | ||
| self._run_forever_flag = False | ||
|
|
||
| async def stop_ws(self): | ||
| self._stop_stream_queue.put_nowait({"should_stop": True}) | ||
|
|
@@ -191,7 +193,8 @@ async def _run_forever(self): | |
| await asyncio.sleep(0.1) | ||
| log.info(f'started {self._name} stream') | ||
| self._running = False | ||
| while True: | ||
| self._run_forever_flag = True | ||
| while self._run_forever_flag: | ||
| try: | ||
| if not self._running: | ||
| log.info("starting websocket connection") | ||
|
|
@@ -376,6 +379,7 @@ def __init__(self, | |
| self._ws = None | ||
| self._running = False | ||
| self._stop_stream_queue = queue.Queue() | ||
| self._run_forever_flag = False | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is the purpose of this flag? What functionality does it add over |
||
|
|
||
| async def _connect(self): | ||
| self._ws = await websockets.connect(self._endpoint) | ||
|
|
@@ -443,7 +447,8 @@ async def _run_forever(self): | |
| await asyncio.sleep(0.1) | ||
| log.info('started trading stream') | ||
| self._running = False | ||
| while True: | ||
| self._run_forever_flag = True | ||
| while self._run_forever_flag: | ||
| try: | ||
| if not self._running: | ||
| log.info("starting websocket connection") | ||
|
|
@@ -466,6 +471,7 @@ async def close(self): | |
| await self._ws.close() | ||
| self._ws = None | ||
| self._running = False | ||
| self._run_forever_flag = False | ||
|
|
||
| async def stop_ws(self): | ||
| self._stop_stream_queue.put_nowait({"should_stop": True}) | ||
|
|
@@ -648,6 +654,22 @@ def run(self): | |
| print('keyboard interrupt, bye') | ||
| pass | ||
|
|
||
| async def _close(self): | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for taking the time to contribute! To help us out, could you please elaborate a bit further on the goal of your PR? |
||
| await asyncio.gather( | ||
| self.stop_ws(), | ||
| self._trading_ws.close(), | ||
| self._data_ws.close(), | ||
| self._crypto_ws.close() | ||
| ) | ||
|
|
||
| def close(self): | ||
| loop = asyncio.get_event_loop() | ||
| try: | ||
| loop.run_until_complete(self._close()) | ||
| except KeyboardInterrupt: | ||
| print('keyboard interrupt, bye') | ||
| pass | ||
|
|
||
| async def stop_ws(self): | ||
| """ | ||
| Signal the ws connections to stop listenning to api stream. | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi 0xfMissingNo! Version changes are necessary in your PR. They are made when we release and deploy a new version.