Exemplo n.º 1
0
    def writeWarning(self, content):
        """快速发出告警日志事件"""
        log = VtLogData()
        log.logContent = content
        event = vn_event(type_=EVENT_WARNING)
        event.dict_['data'] = log
        self.eventEngine.put(event)

        print('{}'.format(datetime.now()), file=sys.stderr)
        print(content, file=sys.stderr)

        # 写入本地log日志
        if self.logger is not None:
            self.logger.warning(content)
        else:
            print(content, file=sys.stderr)
            self.createLogger()

        # 发出邮件
        try:
            sendmail(subject=u'{0} Warning'.format('_'.join(
                self.connected_gw_names)),
                     msgcontent=content)
        except:
            pass
Exemplo n.º 2
0
    def writeCritical(self, content):
        """快速发出严重错误日志事件"""

        log = VtLogData()
        log.logContent = content
        event = vn_event(type_=EVENT_CRITICAL)
        event.dict_['data'] = log
        self.eventEngine.put(event)

        print('{}'.format(datetime.now()), file=sys.stderr)
        print(content, file=sys.stderr)

        # 写入本地log日志
        if self.logger:
            self.logger.critical(content)
        else:
            self.createLogger()

        # 发出邮件
        if globalSetting.get('activate_email',False):
            # 发出邮件
            try:
                sendmail(subject=u'{0} Critical'.format('_'.join(self.connected_gw_names)), msgcontent=content)
            except Exception as ex:
                print(u'vtEngine.writeCritical sendmail Exception:{}'.format(str(ex)), file=sys.stderr)
                print(u'{}'.format(traceback.format_exc()), file=sys.stderr)

        # 发出微信
        if globalSetting.get('activate_wx_ft',False):
            try:
                from huafu.util.util_wx_ft import sendWxMsg
                sendWxMsg(text=content)
            except Exception as ex:
                print(u'vtEngine.writeCritical sendWxMsg Exception:{}'.format(str(ex)), file=sys.stderr)
                print(u'{}'.format(traceback.format_exc()), file=sys.stderr)
Exemplo n.º 3
0
    def qryStatus(self):
        """查询Status"""
        status_dict = OrderedDict()

        # gateway Status
        gw_status_dict = OrderedDict()
        for k, g in self.gatewayDict.items():
            gw_status_dict[k] = g.checkStatus()
        status_dict['gateways'] = gw_status_dict

        # ctaEngine Status
        if self.ctaEngine:
            tick_dict, strategy_dict = self.ctaEngine.qryStatus()
            status_dict['ticks'] = tick_dict
            status_dict['strategies'] = strategy_dict

        # cpu/mem status
        cpuPercent = psutil.cpu_percent()
        memoryPercent = psutil.virtual_memory().percent
        server_info_dict = {'cpu': cpuPercent, 'mem': memoryPercent}
        status_dict['server'] = server_info_dict
        #
        event = vn_event(type_=EVENT_STATUS)
        event.dict_['data'] = status_dict
        self.eventEngine.put(event)

        return True
Exemplo n.º 4
0
    def writeNotification(self, content):
        """快速发出通知日志事件"""
        log = VtLogData()
        log.logContent = content
        event = vn_event(type_=EVENT_NOTIFICATION)
        event.dict_['data'] = log
        self.eventEngine.put(event)

        # 发出邮件
        if globalSetting.get('activate_email', False):
            try:
                sendmail(subject=u'{0} Notification'.format('_'.join(
                    self.connected_gw_names)),
                         msgcontent=content)
            except Exception as ex:
                print(
                    u'vtEngine.writeNotification sendmail Exception:{}'.format(
                        str(ex)),
                    file=sys.stderr)
                print(u'{}'.format(traceback.format_exc()), file=sys.stderr)

        # 发出微信
        if globalSetting.get('activate_wx_ft', False):
            try:
                from huafu.util.util_wx_ft import sendWxMsg
                sendWxMsg(text=content)
            except Exception as ex:
                print(u'vtEngine.writeNotification sendWxMsg Exception:{}'.
                      format(str(ex)),
                      file=sys.stderr)
                print(u'{}'.format(traceback.format_exc()), file=sys.stderr)
Exemplo n.º 5
0
    def qryStatus(self):
        """查询Status"""
        # 状态字典
        status_dict = OrderedDict()

        # 接口状态
        gw_status_dict = OrderedDict()
        for k, g in self.gatewayDict.items():
            # 查询状态
            gw_status_dict[k] = g.checkStatus()

        status_dict['gateways'] = gw_status_dict

        # cta引擎状态
        if self.ctaEngine:
            # 查询ctaEngine的运行状态,返回最新tick字典,策略字典
            tick_dict, strategy_dict = self.ctaEngine.qryStatus()
            status_dict['ticks'] = tick_dict
            status_dict['strategies'] = strategy_dict

        # cpu/mem 状态
        cpuPercent = psutil.cpu_percent()
        memoryPercent = psutil.virtual_memory().percent
        server_info_dict = {'cpu': cpuPercent, 'mem': memoryPercent}
        status_dict['server'] = server_info_dict
        # 状态事件
        event = vn_event(type_=EVENT_STATUS)
        event.dict_['data'] = status_dict
        self.eventEngine.put(event)

        return True
Exemplo n.º 6
0
    def writeCritical(self, content):
        """快速发出严重错误日志事件"""

        log = VtLogData()
        log.logContent = content
        event = vn_event(type_=EVENT_CRITICAL)
        event.dict_['data'] = log
        self.eventEngine.put(event)

        print('{}'.format(datetime.now()), file=sys.stderr)
        print(content, file=sys.stderr)

        # 写入本地log日志
        if self.logger:
            self.logger.critical(content)
        else:
            self.createLogger()

        # 发出邮件
        try:
            sendmail(subject=u'{0} Critical'.format('_'.join(
                self.connected_gw_names)),
                     msgcontent=content)
            from vnpy.trader.util_wx_ft import sendWxMsg
            sendWxMsg(text=content, desp='Critical error')
        except:
            pass
Exemplo n.º 7
0
    def writeError(self, content):
        """快速发出错误日志事件"""
        log = VtErrorData()
        log.errorMsg = content
        event = vn_event(type_=EVENT_ERROR)
        event.dict_['data'] = log
        self.eventEngine.put(event)

        # 写入本地log日志
        logging.error(content)
Exemplo n.º 8
0
    def writeLog(self, content):
        """快速发出日志事件"""
        log = VtLogData()
        log.logContent = content
        event = vn_event(type_=EVENT_LOG)
        event.dict_['data'] = log
        self.eventEngine.put(event)

        # 写入本地log日志
        logging.info(content)
Exemplo n.º 9
0
    def writeLog(self, content):
        """快速发出日志事件"""
        log = VtLogData()
        log.logContent = content
        event = vn_event(type_=EVENT_LOG)
        event.dict_['data'] = log
        self.eventEngine.put(event)

        # 写入本地log日志
        if self.logger is not None:
            self.logger.info(content)
        else:
            self.createLogger()
Exemplo n.º 10
0
    def writeNotification(self, content):
        """快速发出通知日志事件"""
        log = VtLogData()
        log.logContent = content
        event = vn_event(type_=EVENT_NOTIFICATION)
        event.dict_['data'] = log
        self.eventEngine.put(event)

        # 发出邮件
        try:
            sendmail(subject=u'Notification', msgcontent=content)
        except:
            pass
Exemplo n.º 11
0
    def writeError(self, content):
        """快速发出错误日志事件"""
        log = VtErrorData()
        log.errorMsg = content
        event = vn_event(type_=EVENT_ERROR)
        event.dict_['data'] = log
        self.eventEngine.put(event)

        # 写入本地log日志
        if self.logger is not None:
            self.logger.error(content)
        else:
            self.createLogger()
Exemplo n.º 12
0
    def writeWarning(self, content):
        """快速发出告警日志事件"""
        log = VtLogData()
        log.logContent = content
        event = vn_event(type_=EVENT_WARNING)
        event.dict_['data'] = log
        self.eventEngine.put(event)

        # 写入本地log日志
        logging.warning(content)

        # 发出邮件
        try:
            sendmail(subject=u'Warning', msgcontent=content)
        except:
            pass
Exemplo n.º 13
0
    def writeError(self, content):
        """快速发出错误日志事件"""
        log = VtErrorData()
        log.errorMsg = content
        event = vn_event(type_=EVENT_ERROR)
        event.dict_['data'] = log
        self.eventEngine.put(event)

        # 写入本地log日志
        if self.logger is not None:
            self.logger.error(content)
            print('{}'.format(datetime.now()), file=sys.stderr)
            print(content, file=sys.stderr)
        else:
            print(content, file=sys.stderr)
            self.createLogger()
Exemplo n.º 14
0
    def writeCritical(self, content):
        """快速发出严重错误日志事件"""

        log = VtLogData()
        log.logContent = content
        event = vn_event(type_=EVENT_CRITICAL)
        event.dict_['data'] = log
        self.eventEngine.put(event)

        # 写入本地log日志
        logging.critical(content)

        # 发出邮件
        try:
            sendmail(subject=u'Critical', msgcontent=content)
        except:
            pass
Exemplo n.º 15
0
    def writeError(self, content):
        """快速发出错误日志事件"""
        log = VtErrorData()
        log.errorMsg = content
        event = vn_event(type_=EVENT_ERROR)
        event.dict_['data'] = log
        self.eventEngine.put(event)

        # 写入本地log日志
        if self.logger is not None:
            self.logger.error(content)
        else:
            self.createLogger()
        try:
            sendmail(subject=u'{0} Warning'.format('_'.join(self.connected_gw_names)), msgcontent=content)
        except:
            pass
Exemplo n.º 16
0
    def qryStatus(self):
        """查询Status"""
        status_dict = OrderedDict()

        # gateway Status
        gw_status_dict = OrderedDict()
        for k, g in self.gatewayDict.items():
            gw_status_dict[k] = g.checkStatus()
        status_dict['gateways'] = gw_status_dict

        # ctaEngine Status
        if self.ctaEngine:
            tick_dict, strategy_dict = self.ctaEngine.qryStatus()
            status_dict['ticks'] = tick_dict
            status_dict['strategies'] = strategy_dict

        event = vn_event(type_=EVENT_STATUS)
        event.dict_['data'] = status_dict
        self.eventEngine.put(event)

        return True
Exemplo n.º 17
0
    def writeCritical(self, content):
        """快速发出严重错误日志事件"""

        log = VtLogData()
        log.logContent = content
        event = vn_event(type_=EVENT_CRITICAL)
        event.dict_['data'] = log
        self.eventEngine.put(event)

        # 写入本地log日志
        if self.logger:
            self.logger.critical(content)
        else:
            print(content)
            self.createLogger()

        # 发出邮件
        try:
            sendmail(subject=u'{0} Critical'.format(self.connected_gw_name),
                     msgcontent=content)
        except:
            pass
Exemplo n.º 18
0
    def writeError(self, content):
        """快速发出错误日志事件"""
        log = VtErrorData()
        log.errorMsg = content
        event = vn_event(type_=EVENT_ERROR)
        event.dict_['data'] = log
        self.eventEngine.put(event)

        # 写入本地log日志
        if self.logger is not None:
            self.logger.error(content)
        else:
            self.createLogger()

        # 发出邮件
        if globalSetting.get('activate_email', False):
            try:
                sendmail(subject=u'{0} Error'.format('_'.join(
                    self.connected_gw_names)),
                         msgcontent=content)
            except Exception as ex:
                print(u'vtEngine.writeError sendmail Exception:{}'.format(
                    str(ex)),
                      file=sys.stderr)
                print(u'{}'.format(traceback.format_exc()), file=sys.stderr)

        # 发出微信
        if globalSetting.get('activate_wx_ft', False):
            try:
                from huafu.util.util_wx_ft import sendWxMsg
                sendWxMsg(text=content)
            except Exception as ex:
                print(u'vtEngine.writeError sendWxMsg Exception:{}'.format(
                    str(ex)),
                      file=sys.stderr)
                print(u'{}'.format(traceback.format_exc()), file=sys.stderr)