def mergein_instrumentdata_list(cls, client, option_positions): ids = cls._extract_ids(option_positions) idatas = Option.fetch_list(client, ids) results = [] for op in option_positions: idata = [x for x in idatas if x['url'] == op['instrument']][0] # there is an overlap in keys, # {'chain_symbol', 'url', 'type', 'created_at', 'id', # 'updated_at', 'chain_id'} # @TODO this is ugly. let's fix it later # alternative method, # wanted_keys = ['strike_price'] # idata_subset = \ # dict((k, idata[k]) for k in wanted_keys if k in idata) merge_me = { "option_type": idata["type"], "strike_price": idata["strike_price"], "expiration_date": idata["expiration_date"], "min_ticks": idata["min_ticks"] } merged_dict = dict(list(op.items()) + list(merge_me.items())) results.append(merged_dict) return results
def mergein_instrumentdata_list(cls, client, option_events): results = [] ids = [util.get_last_path(oe['option']) for oe in option_events] idatas = Option.fetch_by_ids(client, ids) for oe in option_events: idata = [x for x in idatas if x['url'] == oe['option']][0] merge_me = { "option_type": idata["type"], "symbol": idata["chain_symbol"] } merged_dict = dict(list(oe.items()) + list(merge_me.items())) results.append(merged_dict) return results