From cab8fd1e0e78eb8d5275c8bf7c65fc7011ab761b Mon Sep 17 00:00:00 2001 From: nanoric Date: Tue, 23 Oct 2018 21:29:20 -0400 Subject: [PATCH] =?UTF-8?q?[Mod]=20WebSocket=E6=94=B9=E5=90=8D=E4=B8=BAWeb?= =?UTF-8?q?socket?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/api/base/WebSocketClientTest.py | 4 ++-- vnpy/api/rest/RestClient.py | 6 +++--- .../{WebSocketClient.py => WebsocketClient.py} | 11 +++++++---- vnpy/api/websocket/__init__.py | 2 +- 4 files changed, 13 insertions(+), 10 deletions(-) rename vnpy/api/websocket/{WebSocketClient.py => WebsocketClient.py} (95%) diff --git a/tests/api/base/WebSocketClientTest.py b/tests/api/base/WebSocketClientTest.py index 8d931ecf..dc9651dd 100644 --- a/tests/api/base/WebSocketClientTest.py +++ b/tests/api/base/WebSocketClientTest.py @@ -2,10 +2,10 @@ import unittest from Promise import Promise -from vnpy.api.websocket import WebSocketClient +from vnpy.api.websocket import WebsocketClient -class TestWebsocketClient(WebSocketClient): +class TestWebsocketClient(WebsocketClient): def __init__(self): host = 'wss://echo.websocket.org' diff --git a/vnpy/api/rest/RestClient.py b/vnpy/api/rest/RestClient.py index a013668d..031c6214 100644 --- a/vnpy/api/rest/RestClient.py +++ b/vnpy/api/rest/RestClient.py @@ -88,7 +88,7 @@ class RestClient(object): self.urlBase = urlBase #---------------------------------------------------------------------- - def _generateSession(self): + def _createSession(self): """""" return requests.session() @@ -127,7 +127,7 @@ class RestClient(object): params=None, # type: dict data=None, # type: dict headers=None, # type: dict - onFailed=None, # type: Callable[[dict, Request], Any] + onFailed=None, # type: Callable[[int, Request], Any] extra=None # type: Any ): # type: (...)->Request """ @@ -151,7 +151,7 @@ class RestClient(object): #---------------------------------------------------------------------- def _run(self): - session = self._generateSession() + session = self._createSession() while self._active: try: request = self._queue.get(timeout=1) diff --git a/vnpy/api/websocket/WebSocketClient.py b/vnpy/api/websocket/WebsocketClient.py similarity index 95% rename from vnpy/api/websocket/WebSocketClient.py rename to vnpy/api/websocket/WebsocketClient.py index 7576d5c0..a2e73382 100644 --- a/vnpy/api/websocket/WebSocketClient.py +++ b/vnpy/api/websocket/WebsocketClient.py @@ -11,7 +11,7 @@ import websocket from threading import Lock, Thread -class WebSocketClient(object): +class WebsocketClient(object): """ Websocket API @@ -36,8 +36,6 @@ class WebSocketClient(object): def __init__(self): """Constructor""" self.host = None # type: str - - self._createConnection = websocket.create_connection self._ws_lock = Lock() self._ws = None # type: websocket.WebSocket @@ -70,7 +68,8 @@ class WebSocketClient(object): """ self._active = False self._disconnect() - + + #---------------------------------------------------------------------- def join(self): """ 等待所有工作线程退出 @@ -100,6 +99,10 @@ class WebSocketClient(object): if self._active: self._disconnect() self._connect() + + #---------------------------------------------------------------------- + def _createConnection(self, *args, **kwargs): + return websocket.create_connection(*args, **kwargs) #---------------------------------------------------------------------- def _connect(self): diff --git a/vnpy/api/websocket/__init__.py b/vnpy/api/websocket/__init__.py index 5c44c43f..3accc1ac 100644 --- a/vnpy/api/websocket/__init__.py +++ b/vnpy/api/websocket/__init__.py @@ -1 +1 @@ -from .WebSocketClient import WebSocketClient +from .WebsocketClient import WebsocketClient