def get_comp_data(self, ticker): """ returns all the industries objects in which the given ticker is a part of """ # first get all of the sics the company is a part of self.snapshotXmlReader.set_ticker(ticker) # NOTE - the sics reported via IB ARE NOT THE SAME AS REPORTED IN SEC - thus we use sec for now # comp_sics = self.snapshotXmlReader.get_sics() cont here mofo # {sic_code : text, ...} comp_sics = self.snapshotXmlReader.get_sic_via_sec() industries = {} # get the local SIC dict local_sic_dict = self.get_local_sics_dict() for sic in comp_sics: sic = str(sic) # get the industry obj try: ind_obj = local_sic_dict[sic] except KeyError as e: self.update_local_sic_dict_by_sic(sic) proj_utils.print_warning_msg( "did not found SIC: {} in local dict - updating ".format( sic)) local_sic_dict = self.get_local_sics_dict() ind_obj = local_sic_dict[sic] industries.update({sic: ind_obj}) return industries
def _remove_tickers_data_from_industry_data(self, new_ticker_obj : Ticker_data_c): ticker = new_ticker_obj.get_ticker() # first get old tickers data and compare to new data old_ticker_obj = self.industry_data[ticker] if (old_ticker_obj == new_ticker_obj): return else: old_analyzed_data = old_ticker_obj.get_analyzed_data() num_of_companies = len(self.tickers) for data_name, val in old_analyzed_data.items(): # get the func to do base on data name ("MKCAP, EV...") func_to_perform = self._get_add_remove_function("REMOVE", data_name) val_to_remove = float(val) current_industry_val = float(self.industry_data[data_name]) if func_to_perform == None: proj_utils.print_warning_msg("{}: data name {} was not added to industry data".format(ticker, data_name)) new_ticker_obj.set_in_indutry_avg(data_name, False) else: new_industry_val = func_to_perform(current_industry_val, num_of_companies, val_to_remove) self.industry_data[data_name] = new_industry_val new_ticker_obj.set_in_indutry_avg(data_name, True) return new_ticker_obj
def register_outgoing_req(self, historical): while self._halt_due_to_pacing: cfg.time.sleep(60) proj_utils.print_warning_msg( str(__file__) + ": Halting new requests to avoid pacing issues") if (len(self.avail_requests) == 0): new_avail_requests = [ i for i in range(self.current_requests_ids, self.current_requests_ids * 2) ] # new_avail_requests = new_avail_requests[self.current_requests_ids:] self.current_requests_ids *= 2 self.avail_requests = new_avail_requests outgoind_id = self.avail_requests.pop() outgoind_id = int(outgoind_id) self.outgoing_reqs.update({outgoind_id: OUT}) self.waiting_for_response = True self.reqs_counter -= 1 if (self.reqs_counter == 1): self._halt_due_to_pacing = True return outgoind_id
def _check_max_requests(self): while self.id_handler.get_num_outgoing_reqs( ) >= cfg.IB_MAX_REQUESTS_PER_SEC - 1: # and # self.id_handler: proj_utils.print_warning_msg( f"Holding on request - reached max request per second limit {cfg.IB_MAX_REQUESTS_PER_SEC}" ) cfg.time.sleep(1)
def _add_ticker_data_to_industry_data(self, new_ticker_obj : Ticker_data_c): new_analyzed_data = new_ticker_obj.get_analyzed_data() num_of_companies = len(self.tickers) # print(f"Adding ticker {new_ticker_obj}\n") for data_name, new_val in new_analyzed_data.items(): func_to_perform = self._get_add_remove_function("add",data_name) new_val = float(new_val) if func_to_perform == None: proj_utils.print_warning_msg("{}: data name {} was not added to industry data".format(new_ticker_obj.get_ticker() , data_name)) new_ticker_obj.set_in_indutry_avg(data_name, False) else: try: current_industry_val = float(self.industry_data[data_name]) except: current_industry_val = 0.0 new_industry_val = func_to_perform(current_industry_val, num_of_companies, new_val) self.industry_data[data_name] = new_industry_val return new_ticker_obj