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

unsubscribe_ throws KeyError preventing the rest of symbols to unsubscribe #538

Open
ovresko opened this issue Dec 8, 2021 · 2 comments
Labels
question Further information is requested

Comments

@ovresko
Copy link

ovresko commented Dec 8, 2021

del self._handlers['trades'][symbol]

for symbol in symbols:
del self.handlers['bars'][symbol]
*Symbol KeyError (doesn't exist in handlers,)
this loop should try except or check keys before delete
same for all unsubscribe
* methods

@haxdds
Copy link
Contributor

haxdds commented Dec 21, 2021

Hi overesko, thank you for contributing! Could you provide more information about what context you faced this issue, such as a code snippet?

@haxdds haxdds added the question Further information is requested label Dec 21, 2021
@ovresko
Copy link
Author

ovresko commented Dec 21, 2021

it is obvious, if you have a list of subscribed symbols, and try to unsubscribe them, if one of them is not in self.handlers['bars'] the rest of the loop fails,
pseudo :
symbols = ["AAPL","AMC"... 1000 symbol]
api.subscribe_trades(callback, *symbols)
in case when some of 1000 symbols failed to subscribe or are not valide symbols, when you try to unsubscribe the symbols list it fails with *Symbol KeyError (doesn't exist in handlers,) AND THE UNSUBSCIBING LOOP STOPS it doesn't continue with the rest of them
this loop should be enclosed with try except to let the rest unsubscibe and catch warning text about none existing ones
def unsubscribe_trades(self, *symbols):
if self._running:
asyncio.get_event_loop().run_until_complete(
self._unsubscribe(trades=symbols))
for symbol in symbols:
del self._handlers['trades'][symbol] -------------
try: +++++++++++++++++++++++++++++
del self._handlers['trades'][symbol] +++++++
except:+++++++++++++++++++++++++++
log....++++++++++++++++++++++++++

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants