VeighNa量化社区
你的开源社区量化交易平台
Member
加入于:
帖子: 39
声望: 0

程序是基于 example 里的 no_ui 修改而来

诡异的是大约有一半的时候下是运行到一半自行停止运行

下面是代码

判断是不是处于交易时间

from datetime import datetime, time
from config.common import log
from config.const import WEEK_DICT

Chinese futures market trading period (day/night)

DAY_START = time(8, 45)
DAY_END = time(15, 0)

NIGHT_START = time(20, 45)
NIGHT_END = time(2, 45)

大于等于6 默认是周末

WEEKEND_START = 6
today = datetime.now().weekday() + 1

def is_trading_time():
""""""
current_time = datetime.now().time()
trading = False
if (today < WEEKEND_START):
if (
(current_time >= DAY_START and current_time <= DAY_END)
or (current_time >= NIGHT_START)
or (current_time <= NIGHT_END)
):
trading = True
time = current_time.strftime("%H:%M:%S")

log.info("time:" + time + ' trading:' + str(trading))
return trading



def run_child():
"""
Running in the child process.
"""
SETTINGS["log.file"] = True
SETTINGS.update()

event_engine = EventEngine()
main_engine = MainEngine(event_engine)
main_engine.add_gateway(CtpGateway)
cta_engine = main_engine.add_app(CtaStrategyApp)
main_engine.write_log("主引擎创建成功")

log_engine = main_engine.get_engine("log")
event_engine.register(EVENT_CTA_LOG, log_engine.process_log_event)
main_engine.write_log("注册日志事件监听")

main_engine.connect(ctp_setting, "CTP")
main_engine.write_log("连接CTP接口")

sleep(10)

cta_engine.init_engine()
main_engine.write_log("CTA策略初始化完成")

cta_engine.init_all_strategies()
sleep(60)  # Leave enough time to complete strategy initialization
main_engine.write_log("CTA策略全部初始化")

cta_engine.start_all_strategies()
main_engine.write_log("CTA策略全部启动")

while True:
    sleep(60)

    trading = time_util.is_trading_time()
    if not trading:
        cta_engine.stop_all_strategies()
        log.info("关闭子进程")
        sleep(60)
        main_engine.close()
        sleep(30)
        sys.exit(0)


haha

if name == "main":
run_child()

日志截图

从日志可以看到9.11后就不再打印

description

Member
avatar
加入于:
帖子: 5078
声望: 306

建议可以先跑回没修改的版本看有没有一样的问题,如果没有的话再来逐步排查现在这个脚本的问题

© 2015-2022 上海韦纳软件科技有限公司
备案服务号:沪ICP备18006526号

沪公网安备 31011502017034号

【用户协议】
【隐私政策】
【免责条款】