def setWakeup(self, sender=None, requestedTime=None): # Called by an agent to receive a "wakeup call" from the kernel # at some requested future time. Defaults to the next possible # timestamp. Wakeup time cannot be the current time or a past time. # Sender is required and should be the ID of the agent making the call. # The agent is responsible for maintaining any required state; the # kernel will not supply any parameters to the wakeup() call. if requestedTime is None: requestedTime = self.currentTime + pd.TimeDelta(1) if sender is None: raise ValueError("setWakeup() called without valid sender ID", "sender:", sender, "requestedTime:", requestedTime) if self.currentTime and (requestedTime < self.currentTime): raise ValueError( "setWakeup() called with requested time not in future", "currentTime:", self.currentTime, "requestedTime:", requestedTime) log_print("Kernel adding wakeup for agent {} at time {}", sender, self.fmtTime(requestedTime)) self.messages.put((requestedTime, (sender, MessageType.WAKEUP, None)))
def main(): mode = input('Mode selection (nodata, update, db_init): ') flag_keyboard_interrupt = False engine, session = db.connect() # db_tickers = db.load_available_tickers(session) # TODO db_tickers = [] # testing new_tickers_df = fio.us_equities('resources/generic_backup101518.json') # TODO remove from list according to error csv # TODO remove from list according to db if mode == 'nodata': start_date = pd.to_datetime(params.START_DATE) for ticker_row in new_tickers_df.iterrows( ): # looping over all tickers ticker_row = ticker_row[1] # get rid of the indexing metadata = ticker_row.to_dict() print('Debugging - printing metadata') # debugging print(metadata) # debugging if flag_keyboard_interrupt: # interruption logic print('Keyboard interrupted - exiting...') break if ticker_row[ 'ticker'] not in db_tickers: # skip over existing tickers try: data = dl.get_data(ticker_row['ticker'], start_date=start_date) print(f"Inserting {ticker_row['ticker']} into db" ) # debugging db.insert_data(session, data, metadata=metadata) session.commit() except KeyboardInterrupt as error: flag_keyboard_interrupt = True # except Exception: # can't debug if errors don't show # fio.append_error_csv(ticker_row) # TODO elif mode == 'update': for ticker in db_tickers: if flag_keyboard_interrupt: # ctrl-c break break last_date = db.last_data_date(ticker) # TODO if last_date < pd.Timestamp.today() - pd.TimeDelta(1, 'D'): try: data = dl.get_data(ticker, last_date=last_date) db.insert_table(session, data) # TODO except KeyboardInterrupt as error: flag_keyboard_interrupt = True elif mode == 'db_init': verify = input('You are about to delete everything ' 'in the finance_data database (y/n): ') if verify == 'y': base.metadata.create_all(engine) # create all tables fio.setup_error_csv(verify=True) else: print('Not a valid mode')