量化交易之vnpy篇 - 主力合约换月 - 引擎调用部分

import time
import pandas
import re

from vnpy.trader.tqz_extern.tqz_model import TQZMonitorTimeModel
from vnpy.trader.tqz_extern.tools.position_operator.position_operator import TQZJsonOperator
from vnpy.trader.tqz_extern.tools.symbol_operator.symbol_operator import TQZSymbolOperator

from vnpy.app.tqz_main_contracts_app.tqz_load_main_contracts import (
    TQZTqClient,
    TQZMainContractsChangeFilePath
)
from vnpy.trader.tqz_extern.tqz_constant import (
    TQZMainContractsSheetType,
    TQZMainContractsColumnType,
    TQZMainContractsStrategyPathType,
    TQZMainContractsKeyType,
    TQZWeekDayType
)


class TQZMainContractsEngine:

    def __init__(self, tq_id, tq_password):
        self.tq_id = tq_id
        self.tq_password = tq_password

        self.__today_main_contracts_has_load = False
        self.__today_main_contracts_has_change = False
        self.__current_day = -1


    def tqz_start(self):

        while True:
            # init when new day
            self.__init_today()

            if self.__current_day in [TQZWeekDayType.SATURDAY.value, TQZWeekDayType.SUNDAY.value]:
                if time.localtime().tm_sec is 0 and time.localtime().tm_min is 0:
                    print("today is weekend, no operator to change main contracts")
                pass
            else:
                if self.__is_refresh_time(now_time=time.localtime().tm_sec, interval_time=60):
                    print(time.strftime("%Y/%m/%d  %H:%M:%S", time.localtime()))

                    # load main contracts from tq
                    if TQZMonitorTimeModel.is_load_main_contracts_time() is True:
                        self.__load_main_contracts_from_tq(
                            tq_id=self.tq_id,
                            tq_password=self.tq_password
                        )

                    # change main contract to per path
                    if TQZMonitorTimeModel.is_change_main_contracts_time() is True:
                        self.__change_main_contracts()

            time.sleep(1)


...

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值