Skip to content

Commit

Permalink
Adds functional tests for streaming (#257)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexgolec authored Sep 21, 2021
1 parent aacf029 commit 7c670a8
Showing 1 changed file with 28 additions and 2 deletions.
30 changes: 28 additions & 2 deletions scripts/functional_tests.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
if __name__ == '__main__':
import argparse
import asyncio
import json
import sys
import tda
import unittest

from tda.streaming import StreamClient

tda.debug.enable_bug_report_logging()
import logging
logging.getLogger('').addHandler(logging.StreamHandler())
Expand All @@ -18,6 +21,8 @@ def set_client(cls, client):

@classmethod
def setUpClass(cls):
cls.account_id = args.account_id

# Ensure we never run over an account with funds or assets under it
account = cls.client.get_account(args.account_id).json()
print(json.dumps(account, indent=4))
Expand Down Expand Up @@ -75,8 +80,29 @@ def assert_balances(name):
break


def test_something(self):
pass
def test_streaming(self):
print()
print('##########################################################')
print()
print('Testing stream connection and handling...')

stream_client = StreamClient(self.client, account_id=self.account_id)
async def read_stream():
await stream_client.login()
await stream_client.quality_of_service(StreamClient.QOSLevel.EXPRESS)

stream_client.add_nasdaq_book_handler(
lambda msg: print(json.dumps(msg, indent=4)))
await stream_client.nasdaq_book_subs(['GOOG'])

# Handle one message and then declare victory
await stream_client.handle_message()

asyncio.run(read_stream())

print()
print('##########################################################')
print()


parser = argparse.ArgumentParser('Runs functional tests')
Expand Down

0 comments on commit 7c670a8

Please sign in to comment.