From 5961e458cf83dc9f88828923079036ae71df3a19 Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Tue, 13 Nov 2018 13:23:05 -0500 Subject: [PATCH] Add a option quote latency test --- tests/test_questrade.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/tests/test_questrade.py b/tests/test_questrade.py index fe5a7996..ff60a06c 100644 --- a/tests/test_questrade.py +++ b/tests/test_questrade.py @@ -1,6 +1,9 @@ """ Questrade broker testing """ +import time + +import trio from trio.testing import trio_test from piker.brokers import questrade as qt @@ -133,3 +136,29 @@ async def test_option_chain(tmx_symbols): assert not quote # chains for each symbol were retreived assert not quotes + + +@trio_test +async def test_option_quote_latency(tmx_symbols): + """Audit option quote latencies. + """ + async with qt.get_client() as client: + # all contracts lookup - should be cached + contracts = await client.get_contracts(['WEED.TO']) + + # build single expriry contract + id, by_expiry = next(iter(contracts.items())) + dt, by_strike = next(iter(by_expiry.items())) + single = {id: {dt: by_strike}} + + for expected_latency, contract in [ + (2, contracts), (0.5, single) + ]: + for _ in range(10): + # chains quote for all symbols + start = time.time() + quotes = await client.option_chains(contract) + took = time.time() - start + print(f"Request took {took}") + assert took <= expected_latency + await trio.sleep(0.1)