From 3431b9b15e77592d41f60481ab15f1a78c46fc05 Mon Sep 17 00:00:00 2001 From: "vn.py" Date: Mon, 6 Aug 2018 11:44:32 +0800 Subject: [PATCH] [Fix]Close #885 #953 --- examples/WebTrader/run.py | 7 +++++++ examples/WebTrader/webServer.py | 12 +++++++++--- requirements.txt | 3 ++- 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/examples/WebTrader/run.py b/examples/WebTrader/run.py index 742ca5c3..1bcaa0b9 100644 --- a/examples/WebTrader/run.py +++ b/examples/WebTrader/run.py @@ -9,6 +9,8 @@ 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 vnpy.trader.vtEngine import LogEngine @@ -28,6 +30,9 @@ if __name__ == '__main__': pWeb = None pTrading = None + import os + print(os.getpid()) + while True: le.info('-'*30) @@ -48,6 +53,8 @@ if __name__ == '__main__': pWeb = Process(target=runWebServer) pWeb.start() le.info(u'启动WEB服务器进程') + + webbrowser.open('http://127.0.0.1:5000') else: le.info(u'当前处于非交易时间段') diff --git a/examples/WebTrader/webServer.py b/examples/WebTrader/webServer.py index 18efd35b..411c6cfd 100644 --- a/examples/WebTrader/webServer.py +++ b/examples/WebTrader/webServer.py @@ -50,8 +50,8 @@ with open("WEB_setting.json") as f: # 创建Flask对象 from flask import Flask, send_file -from flask.ext.restful import Api, Resource, reqparse -from flask.ext.socketio import SocketIO +from flask_restful import Api, Resource, reqparse +from flask_socketio import SocketIO from flask_cors import * app = Flask(__name__) @@ -510,6 +510,7 @@ class CtaStrategyStop(Resource): engine.stopStrategy(name) return {'result_code':'success','data':''} + ######################################################################## class CtaStrategyName(Resource): """»ñÈ¡²ßÂÔÃû""" @@ -533,6 +534,7 @@ class CtaStrategyName(Resource): l = engine.getStrategyNames() return {'result_code':'success','data':l} + ######################################################################## class CtaStrategyLoad(Resource): """加载策略""" @@ -672,7 +674,11 @@ ee.register(EVENT_CTA_STRATEGY, handleEvent) #---------------------------------------------------------------------- def run(): """启动Web服务""" - socketio.run(app,debug=True,host='0.0.0.0',port=5000) + socketio.run(app, + debug=True, + host='0.0.0.0', + port=5000, + use_reloader=False) if __name__ == '__main__': diff --git a/requirements.txt b/requirements.txt index a22cf5c1..d2bb6b07 100644 --- a/requirements.txt +++ b/requirements.txt @@ -10,4 +10,5 @@ flask-socketio flask-restful flask-cors gevent-websocket -pyjwt \ No newline at end of file +pyjwt +webbrowser \ No newline at end of file