From 6eca19e3373989c453182660371b304d940213f5 Mon Sep 17 00:00:00 2001 From: "vn.py" Date: Mon, 22 Jan 2018 17:34:49 +0800 Subject: [PATCH] =?UTF-8?q?[Mod]=E5=AE=8C=E5=96=84Websocket=E6=9C=8D?= =?UTF-8?q?=E5=8A=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- examples/WebTrader/run.py | 11 ++++----- examples/WebTrader/test.py | 48 ++++++++++++++++++++++++++++---------- vnpy/__init__.py | 2 +- 3 files changed, 41 insertions(+), 20 deletions(-) diff --git a/examples/WebTrader/run.py b/examples/WebTrader/run.py index 0a7152f3..0533109e 100644 --- a/examples/WebTrader/run.py +++ b/examples/WebTrader/run.py @@ -81,7 +81,7 @@ class Order(Resource): self.postParser.add_argument('offset') self.deleteParser = reqparse.RequestParser() - self.deletaParser.add_argument('vtOrderID') + self.deleteParser.add_argument('vtOrderID') super(Order, self).__init__() @@ -253,10 +253,8 @@ def handleEvent(event): """处理事件""" eventType = event.type_ eventData = event.dict_['data'].__dict__ - #socketio.emit(eventType, eventData, broadcast=True) - socketio.emit('test', eventData, broadcast=True) - - print eventData + socketio.emit(eventType, eventData) + #print eventData ee.register(EVENT_TICK, handleEvent) @@ -272,5 +270,4 @@ ee.register(EVENT_ERROR, handleEvent) if __name__ == '__main__': - app.run(debug=True) - #socketio.run(app) \ No newline at end of file + socketio.run(app) \ No newline at end of file diff --git a/examples/WebTrader/test.py b/examples/WebTrader/test.py index c5be3e68..14dde900 100644 --- a/examples/WebTrader/test.py +++ b/examples/WebTrader/test.py @@ -1,8 +1,10 @@ # encoding: UTF-8 -from socketIO_client import SocketIO, LoggingNamespace +from socketIO_client import SocketIO, BaseNamespace from time import sleep from threading import Thread +import logging + #---------------------------------------------------------------------- def on_connect(): @@ -25,15 +27,37 @@ def on_test(*args): print 'on_test', args +######################################################################## +class TestNamespace(BaseNamespace): + """""" + + #---------------------------------------------------------------------- + def on_connect(self): + """连接""" + print 'on connect' + + #---------------------------------------------------------------------- + def on_disconnect(self): + """断开""" + print 'disconnect' + + #---------------------------------------------------------------------- + def on_reconnect(self): + """重连""" + print 'reconnect' + + #---------------------------------------------------------------------- + def on_message(self, *args): + """测试""" + print 'on_message', args + + + + if __name__ == '__main__': - sio = SocketIO('127.0.0.1', 5000, LoggingNamespace) - sio.on('connect', on_connect) - sio.on('disconnect', on_disconnect) - sio.on('reconnect', on_reconnect) - sio.on('test', on_test) - - t = Thread(target=sio.wait) - t.start() - - while True: - sleep(1) + #logging.getLogger('socketIO-client').setLevel(logging.DEBUG) + #logging.basicConfig() + + sio = SocketIO('127.0.0.1', 5000, TestNamespace, transports='websocket') + sio.wait() + \ No newline at end of file diff --git a/vnpy/__init__.py b/vnpy/__init__.py index ff88771a..6d5daf90 100644 --- a/vnpy/__init__.py +++ b/vnpy/__init__.py @@ -1,4 +1,4 @@ # encoding: UTF-8 -__version__ = '1.7.3' +__version__ = '1.8.0' __author__ = 'Xiaoyou Chen' \ No newline at end of file