def __add_stock(self, msg: Message): if self.is_connected: monitors = execute_read_query(self.connection, 'select acronym from Stocks') monitors = [m[0] for m in monitors] if monitors is not None else [] if msg.payload.acronym not in monitors: print('Adding monitor for {} as well'.format( msg.payload.acronym)) self.requestq.put( Message('vault_request', 'add_monitor', Stock(msg.payload.acronym))) ins_str = setup_record_insertion('ManagedStocks', ManagedStock.get_tuple_names(), [msg.payload.to_tuple_str()]) execute_query(self.connection, ins_str)
def add_stocks(self, msg: Message): if self.is_connected: monitors = execute_read_query(self.connection, 'select acronym from Stocks') monitors = [m[0] for m in monitors] if monitors is not None else [] needs_adding = [] for a in msg.payload: if a.acronym not in monitors: print('Adding monitor for {} as well'.format(a.acronym)) needs_adding.append(Stock(a.acronym)) self.requestq.put( Message('vault_request', 'add_monitors', needs_adding)) ins_str = setup_record_insertion( 'ManagedStocks', ManagedStock.get_tuple_names(), [r.to_tuple_str() for r in msg.payload]) execute_query(self.connection, ins_str)