Exemple #1
0
def run_forever(app):
    """
   永久运行一个APP

    Args:
       app (CtpBee): app实例

    Returns:
       None
    """

    running_me = False
    running_status = True
    while True:
        if not app.p_flag:
            break
        current_time = datetime.now()
        if TradingDay.is_holiday(current_time) or TradingDay.is_weekend(current_time):
            running_me = False
        else:
            running_me = True
        if auth_check_time(current_time):
            pass
        else:
            running_me = False
        if running_me and not running_status:
            """ 到了该启动的时间但是没运行 """
            app.recorder.clear_all()  # 清空记录器中所有的数据
            app.reload()  # 重载接口
            for x in app._extensions.keys():
                app.enable_extension(x)
            print(f"重新进行自动登录, 时间: {str(current_time)}")
            running_status = True

        elif running_me and running_status:
            """ 到了该启动的时间已经在运行 """

        elif not running_me and running_status:
            """ 非交易日 并且在运行 """
            for x in app._extensions.keys():
                app.suspend_extension(x)
                if hasattr(app._extensions[x], "f_init"):
                    app._extensions[x].f_init = False
            print(f"当前时间不允许, 时间: {str(current_time)}, 即将阻断运行")
            running_status = False

        elif not running_me and not running_status:
            """  非交易日 并且不运行 """

        sleep(1)
Exemple #2
0
def run_forever(app):
    """
        永久运行函数 60秒检查一次
        非交易日不进行载入

    """

    running_me = False
    running_status = True

    while True:

        if not app.p_flag:
            break
        current_time = datetime.now()
        if TradingDay.is_holiday(current_time) or TradingDay.is_weekend(
                current_time):
            running_me = False
        else:
            running_me = True
        if auth_check_time(current_time):
            pass
        else:
            running_me = False
        if running_me and not running_status:
            """ 到了该启动的时间但是没运行 """
            app.reload()
            for x in app.extensions.keys():
                app.enable_extension(x)
            print(f"重新进行自动登录, 时间: {str(current_time)}")
            running_status = True

        elif running_me and running_status:
            """ 到了该启动的时间已经在运行 """

        elif not running_me and running_status:
            """ 非交易日 并且在运行 """
            for x in app.extensions.keys():
                app.suspend_extension(x)
            print(f"当前时间不允许, 时间: {str(current_time)}, 即将阻断运行")
            running_status = False

        elif not running_me and not running_status:
            """  非交易日 并且不运行 """

        sleep(1)
Exemple #3
0
def refresh_query(app):
    """ 循环查询 """
    while True:
        sleep(1)
        cur = datetime.now()
        if not TradingDay.is_trading_day(cur) or not auth_check_time(cur):
            continue
        app.query_position()
        sleep(app.config['REFRESH_INTERVAL'])
        app.query_account()
        if not app.r_flag:
            break