def main(): """主程序入口""" args = sys.argv[1:] context = zmq.Context() socket = context.socket(zmq.REQ) socket.connect("tcp://192.168.1.234:9999") socket.send(b"md_front") acc['mdfront'] = socket.recv() socket.send(b"td_front") acc['tdfront'] = socket.recv() socket.send(b"broker_id") acc['brokerid'] = socket.recv() socket.send(b"account_num") acc['account'] = socket.recv() socket.send(b"account_pwd") acc['password'] = socket.recv() socket.send(b"this_symbol") acc['symbol'] = socket.recv() ctypes.windll.shell32.SetCurrentProcessExplicitAppUserModelID( 'vn.py demo') # win7以下请注释掉该行 app = QtGui.QApplication(sys.argv) app.setWindowIcon(QtGui.QIcon('ico.ico')) me = MainEngine() me.set_app(app) me.set_socket(socket) me.set_symbol(acc['symbol']) me.login(acc['account'], acc['password'], acc['brokerid'], acc['mdfront'], acc['tdfront']) mw = MainWindow(me.ee, me) mw.showMaximized() sys.exit(app.exec_())
def ws_ctpaccount(data): global account account = json.loads(data) _store = shelve.open(STORE) _store['ctp_account'] = account _store.close() for k, v in account.items(): if k not in me: _plus = make_plus(v['userid']) me[k] = MainEngine(cs, v, _plus, useZmq=True) print("account " + k + " started")
def main(): """主程序入口""" # ctypes.windll.shell32.SetCurrentProcessExplicitAppUserModelID('vn.py demo') # win7以下请注释掉该行 app = QtGui.QApplication(sys.argv) app.setWindowIcon(QtGui.QIcon('vnpy.ico')) me = MainEngine() mw = Ui(me.ee, me) mw.show() sys.exit(app.exec_())
def main: """演示策略,也可以说是完成策略的函数""" #新建一个Pyqt4对象,用于处理相关事件 app=PyQt4.QcoreApplication(sys.argv) #创建主引擎 me=MainEngine() #向事件驱动引擎中注册打印日志的事件驱动函数 me.ee.register(EVENT_LOG,Print_log) #输入登陆信息 userid=" " password="******" brokerid=" " mdaddress=" " tdaddress=" " #登陆 me.login(userid,password,brokerid,mdaddress,tdaddress) #阻塞10s,用于获取合约等,也可以视情自己调整 sleep(5) #创建策略引擎 se=strategyEngine(me,ee,me) #创建策略 setting={} setting["fastAlpha"]=0.2 setting["slowAlpha"]=0.05 strategyEngine().createStrategy(u"ema策略","TA1601",SimpleEmaStrategy,setting) #运行所有策略 se.startAll() #让程序连续运行 sys.exit(app.exec())
def main(): """运行在CMD中的演示程度""" # 创建PyQt4应用对象 app = QtCore.QCoreApplication(sys.argv) # 创建主引擎对象 me = MainEngine() # 注册事件监听 me.ee.register(EVENT_LOG, print_log) # 登录 userid = '' password = '' brokerid = '' mdAddress = '' tdAddress = '' me.login(userid, password, brokerid, mdAddress, tdAddress) # 等待10秒钟(初始化合约数据等) sleep(5) # 创建策略引擎对象 se = StrategyEngine(me.ee, me) # 创建策略对象 setting = {} setting['fastAlpha'] = 0.2 setting['slowAlpha'] = 0.05 se.createStrategy(u'EMA演示策略', 'IF1506', SimpleEmaStrategy, setting) # 启动所有策略 se.startAll() # 让程序连续运行 sys.exit(app.exec_())
def main(): """主程序入口""" args = sys.argv[1:] context = zmq.Context() socket = context.socket(zmq.REQ) socket.connect("tcp://192.168.1.234:9999") socket.send(b"md_front") acc['mdfront'] = socket.recv() socket.send(b"td_front") acc['tdfront'] = socket.recv() socket.send(b"broker_id") acc['brokerid'] = socket.recv() socket.send(b"account_num") acc['account'] = socket.recv() socket.send(b"account_pwd") acc['password'] = socket.recv() socket.send(b"this_symbol") acc['symbol'] = socket.recv() ctypes.windll.shell32.SetCurrentProcessExplicitAppUserModelID('vn.py demo') # win7以下请注释掉该行 app = QtGui.QApplication(sys.argv) app.setWindowIcon(QtGui.QIcon('ico.ico')) me = MainEngine() me.set_app(app) me.set_socket(socket) me.set_symbol(acc['symbol']) me.login(acc['account'],acc['password'],acc['brokerid'],acc['mdfront'],acc['tdfront']) mw = MainWindow(me.ee, me) mw.showMaximized() sys.exit(app.exec_())
def main(): """运行在CMD中的演示程度""" # 创建PyQt4应用对象 app = QtCore.QCoreApplication(sys.argv) # 创建主引擎对象 me = MainEngine() # 注册事件监听 me.ee.register(EVENT_LOG, print_log) # 登录 userid = '' password = '' brokerid = '' mdAddress = '' tdAddress = '' me.login(userid, password, brokerid, mdAddress, tdAddress) # 等待10秒钟(初始化合约数据等) sleep(5) # 创建策略引擎对象 se = StrategyEngine(me.ee, me) # 创建策略对象 setting = {} setting['fastAlpha'] = 0.2 setting['slowAlpha'] = 0.05 se.createStrategy('EMA演示策略', 'IF1506', SimpleEmaStrategy, setting) # 启动所有策略 se.startAll() # 让程序连续运行 sys.exit(app.exec_())
def main(): """主程序入口""" ctypes.windll.shell32.SetCurrentProcessExplicitAppUserModelID( 'QucikLib') # win7以下请注释掉该行 app = QtGui.QApplication(sys.argv) app.setWindowIcon(QtGui.QIcon('main.ico')) me = MainEngine() mw = MainWindow(me.ee, me) mw.setFixedSize(1000, 620) #设置窗体固定大小 mw.showMaximized() #窗口居中 mw.screen = QtGui.QDesktopWidget().screenGeometry() mw.size = mw.geometry() mw.move((mw.screen.width() - mw.size.width()) / 2, (mw.screen.height() - mw.size.height()) / 2) mw.show() sys.exit(app.exec_())
import Pyro.core from PyQt4.QtCore import QCoreApplication import sys, threading from demoEngine import MainEngine from eventEngine import EventEngine def qtLoop(): daemon.requestLoop() app = QCoreApplication(sys.argv) me = MainEngine() daemon=Pyro.core.Daemon(host='localhost',port=9000) Pyro.core.initServer() proxyOfMainEn = Pyro.core.ObjBase() proxyOfMainEn.delegateTo(me) proxyOfEventEn = Pyro.core.ObjBase() proxyOfEventEn.delegateTo(me.ee) daemon.connect(proxyOfMainEn, 'mainEn') daemon.connect(proxyOfEventEn, 'eventEn') t1 = threading.Thread(target=qtLoop, name='loop') t1.start() app.exec_()