From dc581d0bdcc0601cd8da79d36bf3dcc24fd6eada Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Wed, 26 Dec 2018 13:30:50 -0500 Subject: [PATCH] Handle "adjusted contract" chains per root --- piker/brokers/questrade.py | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/piker/brokers/questrade.py b/piker/brokers/questrade.py index aeed571c..fca579a4 100644 --- a/piker/brokers/questrade.py +++ b/piker/brokers/questrade.py @@ -315,17 +315,28 @@ class Client: contracts.items(), key=lambda item: item[0].expiry ): - by_key[ - ContractsKey( - key.symbol, - key.id, - # converting back - maybe just do this initially? - key.expiry.isoformat(timespec='microseconds'), - ) - ] = { - item['strikePrice']: item for item in - byroot['chainPerRoot'][0]['chainPerStrikePrice'] - } + for chain in byroot['chainPerRoot']: + optroot = chain['optionRoot'] + suffix = '' + + # handle QTs "adjusted contracts" (aka adjusted for + # the underlying in some way; usually has a '(1)' in + # the expiry key in their UI) + adjusted_contracts = optroot != key.symbol + if adjusted_contracts: + suffix = '(' + optroot[len(key.symbol):] + ')' + + by_key[ + ContractsKey( + key.symbol + suffix, + key.id, + # converting back - maybe just do this initially? + key.expiry.isoformat(timespec='microseconds'), + ) + ] = { + item['strikePrice']: item for item in + chain['chainPerStrikePrice'] + } # fill out contract id to strike expiry map for tup, bystrikes in by_key.items():