量化交易之vnpy篇 - 监控模块 - 回调函数监控部分

from remi.server import App, Server
import remi.gui as gui
import time

from vnpy.trader.tqz_extern.tools.position_operator.position_operator import TQZJsonOperator
from vnpy.trader.tqz_extern.tools.file_path_operator.file_path_operator import TQZFilePathOperator

from vnpy.trader.tqz_extern.tqz_model import TQZAccountModel
from vnpy.trader.tqz_extern.tqz_constant import (
    TQZDropdownSelected,
    TQZAccountKeyType,
    TQZMonitorWebDataType,
    TQZWeekDayType
)
from vnpy.trader.tqz_extern.tqz_model import TQZMonitorTimeModel

from vnpy.app.tqz_monitor_app.tqz_auto_report import TQZAutoReport


class TQZMonitorAccountsWeb(App):

    def __init__(self, *args):

        self.__current_hour = -1
        self.__today_main_contracts_has_loaded = False
        self.__pre_accounts_data_dictionary = {}

        self.accounts_data_jsonfile = TQZFilePathOperator.current_file_grandfather_path(
            file=TQZFilePathOperator.grandfather_path(source_path=__file__)
        ) + f'/.vntrader/accounts_data/accounts_data.json'

        self.__yestertay_accounts_data_jsonfile = TQZFilePathOperator.current_file_father_path(
            file=__file__
        ) + f'/yesterday_accounts_data.json'

        super(TQZMonitorAccountsWeb, self).__init__(*args)


    def idle(self):

        if self.__is_refresh_time(now_time=time.localtime().tm_sec, interval_time=5) is True:

            # monitor web: 7(day) X 24(hour);
            self.__web_refresh()

            print(self.__time_now())

            # monitor yesterday_accounts_data part
            self.tqz_monitor_yesterday_accounts_data_jsonfile()

            # monitor auto report part
            self.tqz_monitor_auto_report_part()

    def tqz_monitor_yesterday_accounts_data_jsonfile(self):
        """
        monitor yesterday_accounts_data jsonfile.
        monitor time: 15:30 - 15:35 (7 days)
        """

        if time.localtime().tm_wday in [TQZWeekDayType.SATURDAY.value, TQZWeekDayType.SUNDAY.value]:  # [0, 6]
            return

        if TQZMonitorTimeModel.is_record_settlement_jsonfile_time() is False:
            return

        yesterday_accounts_data = TQZJsonOperator.tqz_load_jsonfile(jsonfile=self.__yestertay_accounts_data_jsonfile)
        if yesterday_accounts_data != self.__pre_accounts_data_list:
            TQZJsonOperator.tqz_write_jsonfile(
                content=self.__pre_accounts_data_list,
                target_jsonfile=self.__yestertay_accounts_data_jsonfile
            )


    def tqz_monitor_auto_report_part(self):
        """
        monitor auto report.
        monitor time: 15:45-20:15 (7 days).
        """

        if TQZMonitorTimeModel.is_auto_report_time() is False:
            return

        if self.__is_refresh_time(
            now_time=time.localtime().tm_sec, interval_time=60
        ) is False:  # monitor frequency of auto report(60s)
            return

        if self.__current_hour is not time.localtime().tm_hour:
            print("self.__current_hour: " + str(self.__current_hour))
            self.__current_hour = time.localtime().tm_hour
            TQZAutoReport.tqz_update(settlement_jsonfile=self.__yestertay_accounts_data_jsonfile)


...

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值