From 5af90c044f51c7bc890b90440ee8cd784316c739 Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Sun, 16 Dec 2018 23:52:10 -0500 Subject: [PATCH] Drop contracts cache; that wasn't the bottleneck This also fixes a bug where option subscriptions weren't actually being changed when a new call was made.. --- piker/brokers/questrade.py | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/piker/brokers/questrade.py b/piker/brokers/questrade.py index 7fa00279..fc75ff56 100644 --- a/piker/brokers/questrade.py +++ b/piker/brokers/questrade.py @@ -5,7 +5,6 @@ import time from datetime import datetime from functools import partial import configparser -from operator import itemgetter from typing import List, Tuple, Dict, Any, Iterator, NamedTuple import trio @@ -418,9 +417,8 @@ async def get_client() -> Client: log.debug("Check time to ensure access token is valid") try: # await client.api.time() - quote = await client.quote(['RY.TO']) - except Exception as err: - # import pdb; pdb.set_trace() + await client.quote(['RY.TO']) + except Exception: # access token is likely no good log.warn(f"Access token {client.access_data['access_token']} seems" f" expired, forcing refresh") @@ -501,18 +499,15 @@ async def option_quoter(client: Client, tickers: List[str]): @async_lifo_cache(maxsize=128) async def get_contract_by_date( sym_date_pairs: Tuple[Tuple[str, str]], - _contract_cache: dict = {} ): """For each tuple, ``(symbol_date_1, symbol_date_2, ... , symbol_date_n)`` return a contract dict. """ symbols, dates = zip(*sym_date_pairs) - if not _contract_cache: - contracts = await client.get_all_contracts(symbols) - _contract_cache.update(contracts) + contracts = await client.get_all_contracts(symbols) selected = {} - for key, val in _contract_cache.items(): + for key, val in contracts.items(): if key.expiry in dates: selected[key] = val