def run(gateway, strategyName): reload(sys) sys.setdefaultencoding('utf-8') """主程序入口""" mainEngine = MainEngine() logPrint = LogPrint(mainEngine) print "connect MongoDB.........." mainEngine.dbConnect() time.sleep(5) print "connet %s.........." % gateway mainEngine.connect(gateway) time.sleep(5) print "start strategy %s......." % strategyName mainEngine.ctaEngine.loadSetting() mainEngine.ctaEngine.initStrategy(strategyName) mainEngine.ctaEngine.startStrategy(strategyName)
def main(): app = QCoreApplication(sys.argv) mainEngine = MainEngine() # 若需要连接数据库,则启动 mainEngine.dbConnect() # 指定的连接配置 mainEngine.connect('CTP_Prod') # 加载cta的配置 mainEngine.ctaEngine.loadSetting() # 初始化策略,如果多个,则需要逐一初始化多个 mainEngine.ctaEngine.initStrategy(u'S26_PTA套利') # 逐一启动策略 mainEngine.ctaEngine.startStrategy(u'S26_PTA套利') logM = LogMonitor(mainEngine.eventEngine) errorM = ErrorMonitor(mainEngine.eventEngine) tradeM = TradeMonitor(mainEngine.eventEngine) orderM = OrderMonitor(mainEngine.eventEngine, mainEngine) positionM = PositionMonitor(mainEngine.eventEngine) accountM = AccountMonitor(mainEngine.eventEngine) app.exec_()
def main(): """主程序入口""" # 重载sys模块,设置默认字符串编码方式为utf8 reload(sys) sys.setdefaultencoding('utf8') # 设置Windows底部任务栏图标 if platform.uname() == 'Windows': ctypes.windll.shell32.SetCurrentProcessExplicitAppUserModelID('vn.trader') # 初始化Qt应用对象 app = QtCore.QCoreApplication(sys.argv) # 初始化主引擎和主窗口对象 mainEngine = MainEngine() # 在主线程中启动Qt事件循环 sys.exit(app.exec_()) # 连接mongo数据库 mainEngine.dbConnect() # 连接CTP接口 mainEngine.connect('CTP')
import pandas as pd import vtPath from ctaBase import * from ctaStrategy import ctaEngine2 #from data.loader import DataLoader from data.csv_loader import DataLoader from gateway import GATEWAY_DICT from vtEngine import MainEngine __BAR__ = False if __name__ == '__main__': mainEngine = MainEngine() mainEngine.dbConnect() drEngine = mainEngine.drEngine drEngine.loadSetting() dl = DataLoader() if __BAR__: # ru #df_rs = dl.LoadBar('ru1305', '20130104', '20130218', bin='1min') #df_rs = dl.LoadBar('ru1309', '20130219', '20130627', bin='1min') #df_rs = dl.LoadBar('ru1401', '20130628', '20131103', bin='1min') #df_rs = dl.LoadBar('ru1405', '20131104', '20140227', bin='1min') #df_rs = dl.LoadBar('ru1409', '20140228', '20140722', bin='1min') #df_rs = dl.LoadBar('ru1501', '20140723', '20141120', bin='1min') #df_rs = dl.LoadBar('ru1505', '20141121', '20150303', bin='1min') #df_rs = dl.LoadBar('ru1509', '20150304', '20150715', bin='1min') #df_rs = dl.LoadBar('ru1601', '20150716', '20151125', bin='1min') #df_rs = dl.LoadBar('ru1605', '20151126', '20160320', bin='1min')
class EventLoopManager(object): def __init__(self): self.makeLog('Event loop manager started', False) self.engineStarted = False self.mainEngine = MainEngine() self.eventEngine = EventEngine2() # 注册事件监听 self.registerEvent() self.mainEngine.dbConnect() time.sleep(2) ''' self.mainEngine.connect('CTP') time.sleep(3) self.mainEngine.ctaEngine.loadSetting() self.mainEngine.ctaEngine.initStrategy('double ema') ''' self.eventEngine.start() def start(self): self.eventEngine.start() # 注册事件监听 self.registerEvent() def onEventLog(self, event): log = event.dict_['data'] logContent = ' '.join([log.logTime, log.logContent, '\n']) self.makeLog(logContent) def onEventTimer(self, event): today = date.weekday(datetime.now().date()) if today == 5 or today == 6:#weekends return hour = datetime.now().hour #log in if(self.engineStarted == False and (hour in [9, 10, 11, 13, 20, 21, 22, 23, 24, 1])#trading hour ): #self.makeLog('Starting CTP double ema') self.run() return time.sleep(2) #log out if(self.engineStarted == True and (hour in [14, 2]) ): #self.makeLog('Ending CTP double ema') self.stop() return def registerEvent(self): """注册事件监听""" self.mainEngine.eventEngine.register(EVENT_LOG, self.onEventLog) self.mainEngine.eventEngine.register(EVENT_CTA_LOG, self.onEventLog) self.eventEngine.register(EVENT_TIMER, self.onEventTimer) #self.makeLog('Events registerred',False) def run(self): self.mainEngine.connect('CTP') time.sleep(3) self.mainEngine.drEngine.loadSetting() self.mainEngine.ctaEngine.loadSetting() self.mainEngine.ctaEngine.initStrategy('double ema') self.mainEngine.ctaEngine.startStrategy('double ema') self.engineStarted = True def stop(self): try: #self.mainEngine.ctaEngine.stopStrategy('double ema') #self.mainEngine.exit() #time.sleep(2) self.engineStarted = False except Exception as e: print e def makeLog(self, content, sendemail = False): if sendemail == True: send_email(subject = content) print content