Path: blob/master/ invest-robot-contest_TradingCompetition2022-main/logger/BusinessLogger.py
5925 views
from logger.Logger import Logger, LogData1from datetime import datetime234class BusinessLogger(Logger):5"""6Singleton Class for data logging7Collect all event8"""9ORDER_POSTED = "ORDER_POSTED"10ORDER_OPEN_LONG_DONE = "ORDER_OPEN_LONG_DONE"11ORDER_CLOSE_LONG_DONE = "ORDER_CLOSE_LONG_DONE"12ACCOUNT_STARTED = "ACCOUNT_STARTED"13ACCOUNT_BALANCE_NO_MONEY = "ACCOUNT_BALANCE_NO_MONEY"14STOCK_IN_WORK = "STOCK_IN_WORK"15STOCK_RE_INIT = "STOCK_RE_INIT"16STOCK_DEL_FROM_SESS = "STOCK_DEL_FROM_SESSION"17MODEL_CREATED = "MODEL_CREATED"18CALC_STOP = "CALC_STOP"19STOP_LOOS = "STOP_LOOS"20TAKE_PROFIT = "TAKE_PROFIT"2122_LOGGER_INSTANCE: object = None23log_line_dict = dict(datetime=datetime.now(), msg="")2425def __init__(self, conf_name_print_mode=None):26if conf_name_print_mode is None:27conf_name_print_mode = 'print_business_log'28super().__init__(conf_name_print_mode)2930@classmethod31def get_logger_instance(cls):32if cls._LOGGER_INSTANCE is None:33cls._LOGGER_INSTANCE = BusinessLogger()34return cls._LOGGER_INSTANCE3536def add_event(self, event_type, obj, value=None):37key = obj.id if hasattr(obj, 'id') else obj38if value is None:39value = obj40log_data = LogData(event_id=event_type, key=key, value=value)41self.add_log(log_data)4243def add_event_no_money(self, obj, balance, need_money):44self.add_event(BusinessLogger.ACCOUNT_BALANCE_NO_MONEY,45obj, dict(balance=balance, need_money=need_money))464748