Ejemplo n.º 1
0
def main():
    """主程序入口"""
    le = LogEngine()
    le.setLogLevel(le.LEVEL_INFO)
    le.addConsoleHandler()
    le.addFileHandler()

    le.info(u'服务器进程启动')

    # 创建事件引擎
    ee = EventEngine2()
    le.info(u'事件引擎创建成功')

    # 创建主引擎
    me = MainEngine(ee)

    # 添加交易接口
    me.addGateway(ctpGateway)

    # 添加上层应用
    me.addApp(ctaStrategy)
    me.addApp(rpcService)

    le.info(u'主引擎创建成功')

    # 阻塞运行
    le.info(u'服务器启动成功')
    while 1:
        sleep(1)
Ejemplo n.º 2
0
def main():
    """主程序入口"""
    le = LogEngine()
    le.setLogLevel(le.LEVEL_INFO)
    le.addConsoleHandler()
    le.addFileHandler()

    le.info(u'服务器进程启动')

    # 创建事件引擎
    ee = EventEngine2()
    le.info(u'事件引擎创建成功')

    # 创建主引擎
    me = MainEngine(ee)

    # 安全退出机制
    def shutdown(signal, frame):
        le.info(u'安全关闭进程')
        me.exit()
        sys.exit()

    for sig in [signal.SIGINT, signal.SIGTERM]:
        signal.signal(sig, shutdown)

    # 添加交易接口
    me.addGateway(ctpGateway)

    # 添加上层应用
    me.addApp(ctaStrategy)
    me.addApp(rpcService)

    le.info(u'主引擎创建成功')

    # 阻塞运行
    le.info(u'服务器启动成功')
    while 1:
        sleep(1)
Ejemplo n.º 3
0
def runParentProcess():
    """父进程运行函数"""
    # 创建日志引擎
    le = LogEngine()
    le.setLogLevel(le.LEVEL_INFO)
    le.addConsoleHandler()

    le.info(u'启动CTA策略守护父进程')

    DAY_START = time(8, 45)  # 日盘启动和停止时间
    DAY_END = time(15, 30)

    NIGHT_START = time(20, 45)  # 夜盘启动和停止时间
    NIGHT_END = time(2, 45)

    p = None  # 子进程句柄

    while True:
        currentTime = datetime.now().time()
        recording = False

        # 判断当前处于的时间段
        if ((currentTime >= DAY_START and currentTime <= DAY_END)
                or (currentTime >= NIGHT_START) or (currentTime <= NIGHT_END)):
            recording = True

        # 过滤周末时间段:周六全天,周五夜盘,周日日盘
        if ((datetime.today().weekday() == 6) or
            (datetime.today().weekday() == 5 and currentTime > NIGHT_END) or
            (datetime.today().weekday() == 0 and currentTime < DAY_START)):
            recording = False

        # 记录时间则需要启动子进程
        if recording and p is None:
            le.info(u'启动子进程')
            p = multiprocessing.Process(target=runChildProcess)
            p.start()
            le.info(u'子进程启动成功')

        # 非记录时间则退出子进程
        if not recording and p is not None:
            le.info(u'关闭子进程')
            p.terminate()
            p.join()
            p = None
            le.info(u'子进程关闭成功')

        sleep(5)
Ejemplo n.º 4
0
def runChildProcess():
    """子进程运行函数"""
    print('-' * 20)

    # 创建日志引擎
    le = LogEngine()
    le.setLogLevel(le.LEVEL_INFO)
    le.addConsoleHandler()
    le.addFileHandler()

    le.info(u'启动CTA策略运行子进程')

    ee = EventEngine2()
    le.info(u'事件引擎创建成功')

    me = MainEngine(ee)
    me.addGateway('CTP')
    me.addApp(ctaStrategy)
    le.info(u'主引擎创建成功')

    ee.register(EVENT_LOG, le.processLogEvent)
    ee.register(EVENT_CTA_LOG, le.processLogEvent)
    ee.register(EVENT_ERROR, processErrorEvent)
    le.info(u'注册日志事件监听')

    me.connect('CTP')
    le.info(u'连接CTP接口')

    sleep(10)  # 等待CTP接口初始化
    me.dataEngine.saveContracts()  # 保存合约信息到文件

    cta = me.getApp(ctaStrategy.appName)

    cta.loadSetting()
    le.info(u'CTA策略载入成功')

    cta.initAll()
    le.info(u'CTA策略初始化成功')

    cta.startAll()
    le.info(u'CTA策略启动成功')

    while True:
        sleep(1)
Ejemplo n.º 5
0
def runChildProcess():
    """子进程运行函数"""
    print('-'*20)

    # 创建日志引擎
    le = LogEngine()
    le.setLogLevel(le.LEVEL_INFO)
    le.addConsoleHandler()
    le.info(u'启动行情记录运行子进程')
    
    ee = EventEngine2()
    le.info(u'事件引擎创建成功')
    
    me = MainEngine(ee)
    me.addGateway('CTP')
    me.addApp(dataRecorder)
    le.info(u'主引擎创建成功')

    ee.register(EVENT_LOG, le.processLogEvent)
    ee.register(EVENT_ERROR, processErrorEvent)
    le.info(u'注册日志事件监听')

    me.connect('CTP')
    le.info(u'连接CTP接口')

    has_recorder_day = False
    while True:
        sleep(1)
        if has_recorder_day == False:
            time_now = datetime.now()
            if time_now.time().hour ==15 and time_now.time().minute > 5:
                event1 = Event(type_=EVENT_RECORDER_DAY)
                ee.put(event1)
                has_recorder_day = True
Ejemplo n.º 6
0
from time import sleep
from datetime import datetime, time
from multiprocessing import Process

import webbrowser

from webServer import run as runWebServer
from tradingServer import main as runTradingServer
from cyvn.trader.vtEngine import LogEngine

START_TIME = time(20, 45)
CLOSE_TIME = time(15, 30)

if __name__ == '__main__':
    # 创建日志引擎
    le = LogEngine()
    le.setLogLevel(le.LEVEL_INFO)
    le.addConsoleHandler()

    # 进入循环
    pWeb = None
    pTrading = None

    import os
    print(os.getpid())

    while True:
        le.info('-' * 30)

        dt = datetime.now()
        le.info(u'当前时间:%s' % dt)