From 2f9af196a8925fbf9bddc37fabc8f9529dc2935e Mon Sep 17 00:00:00 2001 From: "vn.py" Date: Tue, 13 Feb 2018 17:22:42 +0800 Subject: [PATCH] =?UTF-8?q?[Add]=E5=A2=9E=E5=8A=A0WebTrader=E7=9A=84?= =?UTF-8?q?=E4=B8=BB=E9=A1=B5=E8=B7=AF=E7=94=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- examples/WebTrader/run.py | 33 ++++++++++++++----- .../WebTrader/{web => static}/css/style.css | 0 .../WebTrader/{web => templates}/index.html | 2 +- 3 files changed, 26 insertions(+), 9 deletions(-) rename examples/WebTrader/{web => static}/css/style.css (100%) rename examples/WebTrader/{web => templates}/index.html (99%) diff --git a/examples/WebTrader/run.py b/examples/WebTrader/run.py index 0072391e..8ea79db6 100644 --- a/examples/WebTrader/run.py +++ b/examples/WebTrader/run.py @@ -56,7 +56,6 @@ api = Api(app) socketio = SocketIO(app) # 创建资源 - ######################################################################## class Token(Resource): """登录验证""" @@ -204,16 +203,33 @@ class Order(Resource): vtOrderID = args['vtOrderID'] - order = me.getOrder(vtOrderID) - if not order: - return {'result_code':'error','message':'vtOrderID error'} - + # 撤单某一委托 + if vtOrderID: + order = me.getOrder(vtOrderID) + if not order: + return {'result_code':'error','message':'vtOrderID error'} + + self.cancel(order) + # 全撤 + else: + l = me.getAllWorkingOrders() + + for order in l: + self.cancel(order) + + return {'result_code':'success','data':""} + + #---------------------------------------------------------------------- + def cancel(self, order): + """撤单""" req = VtCancelOrderReq() req.orderID = order.orderID req.exchange = order.exchange req.symbol = order.symbol - me.cancelOrder(req, order.gatewayName) - return {'result_code':'success','data':""} + req.frontID = order.frontID + req.sessionID = order.sessionID + me.cancelOrder(req, order.gatewayName) + ######################################################################## class Trade(Resource): @@ -598,7 +614,8 @@ class CtaStrategyVar(Resource): @app.route('/') def index_html(): """首页""" - return send_file( os.path.abspath('.') + '/web/index.html' ) + return send_file('./templates/index.html') + # 注册资源 api.add_resource(Token, '/token') diff --git a/examples/WebTrader/web/css/style.css b/examples/WebTrader/static/css/style.css similarity index 100% rename from examples/WebTrader/web/css/style.css rename to examples/WebTrader/static/css/style.css diff --git a/examples/WebTrader/web/index.html b/examples/WebTrader/templates/index.html similarity index 99% rename from examples/WebTrader/web/index.html rename to examples/WebTrader/templates/index.html index 836d3abd..6aaa512e 100644 --- a/examples/WebTrader/web/index.html +++ b/examples/WebTrader/templates/index.html @@ -5,7 +5,7 @@ - +