def __save_balances_to_database__(self): if len(self._balance_saving_times) == 0: # already all done return processed_list = [] ts_now = MyDate.get_epoch_seconds_from_datetime() for ts_saving in self._balance_saving_times: if ts_saving <= ts_now: dt_saving = MyDate.get_date_time_from_epoch_seconds_as_string(ts_saving) self.__save_balances__(ts_saving, dt_saving) processed_list.append(ts_saving) for values in processed_list: self._balance_saving_times.remove(values)
def get_balance_as_asset_data_frame(self): if self.balances is None: return None ts = MyDate.get_epoch_seconds_from_datetime() dt_str = MyDate.get_date_time_from_epoch_seconds_as_string(ts) dict_for_data_frame = {} for balance in self.balances: data_dict = AssetDataDictionary( ).get_data_dict_for_target_table_for_balance(balance, ts, dt_str) for key, value in data_dict.items(): if key not in dict_for_data_frame: dict_for_data_frame[key] = [value] else: dict_for_data_frame[key].append(value) return pd.DataFrame.from_dict(dict_for_data_frame)
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 get_date_time_for_retracement_pct(self, retracement_pct: float) -> str: ts = self.get_timestamp_for_retracement_pct(retracement_pct) if self.period == PRD.DAILY: return str(MyDate.get_date_from_epoch_seconds(ts)) return MyDate.get_date_time_from_epoch_seconds_as_string(ts)