Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only call the news handler once for a single message #693

Merged
merged 1 commit into from
Mar 28, 2023
Merged
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
5 changes: 4 additions & 1 deletion alpaca_trade_api/stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,8 @@ async def _dispatch(self, msg):
msg_type = msg.get('T')
if msg_type == 'n':
symbols = msg.get('symbols', [])
# A news article could be unrelated to any symbols, resulting in an empty symbols list. Those news articles
# A news article could be unrelated to any symbols,
# resulting in an empty symbols list. Those news articles
# should still be dispatched to the wildcard event handler.
if not symbols:
symbols.append('*')
Expand All @@ -579,6 +580,8 @@ async def _dispatch(self, msg):

if handler is not None:
await handler(self._cast(msg_type, msg))
# For a single message, only call the handler once
break
else:
await super()._dispatch(msg)

Expand Down