예제 #1
0
    def __init__(self, repAddress, pubAddress):
        """Constructor"""
        super(VtServer, self).__init__(repAddress, pubAddress)
        self.usePickle()

        # 创建事件引擎
        self.ee = EventEngine2()

        # 创建主引擎对象
        self.engine = MainEngine(self.ee)

        # 注册主引擎的方法到服务器的RPC函数
        self.register(self.engine.connect)
        self.register(self.engine.subscribe)
        self.register(self.engine.sendOrder)
        self.register(self.engine.cancelOrder)
        self.register(self.engine.qryAccount)
        self.register(self.engine.qryPosition)
        self.register(self.engine.exit)
        self.register(self.engine.writeLog)
        self.register(self.engine.dbConnect)
        self.register(self.engine.dbInsert)
        self.register(self.engine.dbQuery)
        self.register(self.engine.dbUpdate)
        self.register(self.engine.getContract)
        self.register(self.engine.getAllContracts)
        self.register(self.engine.getOrder)
        self.register(self.engine.getAllWorkingOrders)
        self.register(self.engine.getAllGatewayDetails)

        # 注册事件引擎发送的事件处理监听
        self.engine.eventEngine.registerGeneralHandler(self.eventHandler)
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)
예제 #3
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(ctpGateway)
    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接口')

    while True:
        sleep(1)
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(ctpGateway)
    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接口初始化

    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)
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)
예제 #6
0
def main():
    """客户端主程序入口"""
    # 创建Qt对象
    qApp = createQApp()

    # 创建事件引擎
    eventEngine = EventEngine2()
    eventEngine.start(timer=False)

    # 创建客户端
    reqAddress = 'tcp://localhost:2014'
    subAddress = 'tcp://localhost:0602'
    client = VtClient(reqAddress, subAddress, eventEngine)

    client.subscribeTopic('')
    client.start()

    # 初始化主引擎和主窗口对象
    mainEngine = ClientEngine(client, eventEngine)
    mainWindow = MainWindow(mainEngine, mainEngine.eventEngine)
    mainWindow.showMaximized()

    # 在主线程中启动Qt事件循环
    sys.exit(qApp.exec_())
예제 #7
0
reload(sys)
sys.setdefaultencoding('utf8')

# 创建主引擎代理对象
from event import EventEngine2
from trader.vtEvent import (EVENT_TICK, EVENT_ORDER, EVENT_TRADE,
                            EVENT_ACCOUNT, EVENT_POSITION, EVENT_LOG,
                            EVENT_ERROR, EVENT_CONTRACT)
from trader.vtObject import VtSubscribeReq, VtOrderReq, VtCancelOrderReq
from app.rpcService.rsClient import MainEngineProxy
from app.ctaStrategy.ctaBase import EVENT_CTA_LOG, EVENT_CTA_STRATEGY

reqAddress = 'tcp://localhost:6688'
subAddress = 'tcp://localhost:8866'

ee = EventEngine2()
me = MainEngineProxy(ee)
me.init(reqAddress, subAddress)


#----------------------------------------------------------------------
def printLog(event):
    """打印日志"""
    log = event.dict_['data']
    print log.logTime, log.logContent


ee.register(EVENT_LOG, printLog)

# 载入Web密码
import json