def __log_message__(self, file_path, log_message: str, process='', process_step='run'):
     if not self.log_activated:
         print('File_log is deactivated')
         return
     for old, new in {',': ' ', '; ': ' ', '  ': ' ', '\n': ' ', '"': ''}.items():
         log_message = log_message.replace(old, new).strip()
     log_message = log_message.strip()
     process = 'logging' if process == '' else process
     date_time = MyDate.get_date_time_as_string_from_date_time()
     date_time_parts = date_time.split(' ')
     line_list = [date_time_parts[0], date_time_parts[1], process, process_step, log_message]
     with open(file_path, 'a') as file:  # write append mode
         file.write('{}\n'.format(','.join(line_list)))
 def get_historical_data_by_client(self):
     self.wrapper.init_historical_data_queue()
     date_from = MyDate.adjust_by_days(MyDate.get_datetime_object(), -180)
     date_from_str = MyDate.get_date_time_as_string_from_date_time(
         date_from, '%Y%m%d %H:%M:%S')
     print(date_from_str)
     qqq = Contract()
     qqq.symbol = 'MMEN'
     qqq.secType = 'STK'
     qqq.exchange = 'CSE'
     qqq.currency = 'CAD'
     self.reqHistoricalData(4001, qqq, date_from_str, "1 M", "1 day",
                            "MIDPOINT", 1, 1, False, [])
     return self.wrapper.get_historical_data()
示例#3
0
 def check_tasks(self):
     date_time_str = MyDate.get_date_time_as_string_from_date_time()
     if not self._for_test:
         SalesmanLog().log_scheduler_process('__check_scheduled_jobs__',
                                             process='Scheduler',
                                             process_step='Start')
     print("{}: Checking for scheduled tasks at {}".format(
         self._process, date_time_str))
     if self._last_run_time_stamp is not None:
         for job in self._job_list:
             if job.is_ready(self._last_run_time_stamp):
                 print('...{}: Starting job: {}'.format(
                     self._process, job.job_name))
                 job.start_job()
     self._last_run_time_stamp = MyDate.time_stamp_now()
     self._last_run_date_time = MyDate.get_date_time_from_epoch_seconds_as_string(
         self._last_run_time_stamp)
 def log_waiting_db_transaction(self, table_name: str, data_dict_list: list):
     message = 'Transaction problem at {}'.format(MyDate.get_date_time_as_string_from_date_time())
     data_dict_list_str = '{}'.format(data_dict_list)
     data_dict_list_str = data_dict_list_str.replace(',', '#')        
     self.__log_message__(
         self.__get_file_path_for_waiting_db_transactions__(), message, table_name, data_dict_list_str)
    test_function_01(4), undefined_process.get_statistics()))

# @PatternProcessManager.processmethod(update_trade_process)
# def test_function(number: int, process=None):
#     process.increment_processed_records()
#     process.increment_inserted_records()
#     return number * 2
#
#
# print('test_function={}, statistics={}'.format(test_function(4), update_trade_process.get_statistics()))

for_dash_test = False
if for_dash_test:
    my_handler = MyDashJobHandler(process_manager, for_test=True)
    my_handler.check_scheduler_tasks()
else:
    scheduler = MyPatternScheduler('PatternSchedulerTest',
                                   process_manager,
                                   for_test=True)
    scheduler.add_job(
        MyPatternJob(period=PRD.DAILY,
                     weekdays=weekday_list,
                     start_times=start_time_list))
    # scheduler.add_job(MySecondJob(period=PRD.DAILY, weekdays=weekday_list, start_time=start_time))
    for k in range(4):
        scheduler.check_tasks()
        print('{}: Waiting main process for {} seconds...'.format(
            MyDate.get_date_time_as_string_from_date_time(),
            scheduler_run_interval_sec))
        sleep(scheduler_run_interval_sec)
process_manager.print_statistics()
示例#6
0
 def stop(self):
     self._end_date_time = MyDate.get_date_time_as_string_from_date_time()
     self._end_ts = MyDate.get_epoch_seconds_from_datetime()