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

Streaming example in docs/streaming.rst adding wrong handler #114

Closed
realumhelp opened this issue Sep 30, 2020 · 2 comments · May be fixed by #116
Closed

Streaming example in docs/streaming.rst adding wrong handler #114

realumhelp opened this issue Sep 30, 2020 · 2 comments · May be fixed by #116

Comments

@realumhelp
Copy link

Description of Bug
The example listed in docs/streaming.rst will not display any data because it is subscribing to nasdaq_book_subs but adding a handler for add_timesale_options_handler. Also recommend re-organizing the code to make it a bit easier to reconnect to the Websocket without re-adding handlers.

Expected Behavior
Expected example to add handler to: add_nasdaq_book_handler

Actual Behavior
No data is generated

from tda.auth import easy_client
from tda.client import Client
from tda.streaming import StreamClient

import asyncio
import json

client = easy_client(
        api_key='APIKEY',
        redirect_uri='https://localhost',
        token_path='/tmp/token.pickle')
stream_client = StreamClient(client, account_id=1234567890)
stream_client.add_nasdaq_book_handler(
            lambda msg: print(json.dumps(msg, indent=4)))

async def read_stream():
    await stream_client.login()
    await stream_client.quality_of_service(StreamClient.QOSLevel.EXPRESS)
    await stream_client.nasdaq_book_subs(['GOOG'])

    while True:
        await stream_client.handle_message()

asyncio.get_event_loop().run_until_complete(read_stream())
@realumhelp
Copy link
Author

Looks like the bug in the docs has actually been fixed already here:
20bbcf7#diff-fceaae0ff594b2a5dee31140ef4e421a

I moved the add_handler call outside of read_stream to help users who want to reconnect to the stream if it fails. It gives them a little bit better base to start from. It also prevents a potential race condition where nasdaq_book_subs could send data faster than the handler could actually get registered.

@alexgolec
Copy link
Owner

The original issue has been resolved. Please feel free to reopen an issue for your other concern.

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

Successfully merging a pull request may close this issue.

2 participants