From c4d1da3045672d330a7c2a2a1f934cbb6f5822f2 Mon Sep 17 00:00:00 2001 From: nanoric Date: Sun, 7 Oct 2018 03:58:14 -0400 Subject: [PATCH] =?UTF-8?q?[Mod]=20=E5=B0=86RestfulClient=E5=92=8CWebSocke?= =?UTF-8?q?tClient=E7=9A=84=E6=9E=84=E9=80=A0=E5=92=8C=E5=88=9D=E5=A7=8B?= =?UTF-8?q?=E5=8C=96=E5=88=86=E7=A6=BB=E5=BC=80=E6=9D=A5=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- vnpy/restful/RestfulClient.py | 20 +++++++++++++++----- vnpy/restful/WebSocketClient.py | 7 +++++-- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/vnpy/restful/RestfulClient.py b/vnpy/restful/RestfulClient.py index ab15ca17..5a3cc3aa 100644 --- a/vnpy/restful/RestfulClient.py +++ b/vnpy/restful/RestfulClient.py @@ -54,19 +54,29 @@ class Request(object): class RestfulClient(object): #---------------------------------------------------------------------- - def __init__(self, urlBase, sessionProvider): + def __init__(self): """ :param urlBase: 路径前缀。 例如'https://www.bitmex.com/api/v1/' - :param sessionProvider: callable。调用后应该返回一个对象带request函数的对象,该request函数的用法应该和requests中的一致。\ - 每个工作线程会调用该函数一次以期获得一个独立的session实例。可以选择requestsSessionProvider。 """ - self.urlBase = urlBase # type: str + self.urlBase = None # type: str + self.sessionProvider = requestsSessionProvider self._active = False self._queue = Queue() self._pool = None # type: Pool - + + #---------------------------------------------------------------------- + def init(self, urlBase): + self.urlBase = urlBase + + #---------------------------------------------------------------------- + def setSessionProvider(self, sessionProvider): + """ + 设置sessionProvider可以使用自定义的requests实现。 + @:param sessionProvider: callable。调用后应该返回一个对象带request函数的对象,该request函数的用法应该和requests中的一致。 \ + 每个工作线程会调用该函数一次以期获得一个独立的session实例。 + """ self.sessionProvider = sessionProvider #---------------------------------------------------------------------- diff --git a/vnpy/restful/WebSocketClient.py b/vnpy/restful/WebSocketClient.py index 76b3d0f8..60ba8831 100644 --- a/vnpy/restful/WebSocketClient.py +++ b/vnpy/restful/WebSocketClient.py @@ -16,12 +16,16 @@ class WebsocketClient(object): """Websocket API""" #---------------------------------------------------------------------- - def __init__(self, host): + def __init__(self): """Constructor""" self.ws = None # type: websocket.WebSocket self.workerThread = None # type: Thread self.pingThread = None # type: Thread self.active = False + self.host = None # type: str + + #---------------------------------------------------------------------- + def init(self, host): self.host = host #---------------------------------------------------------------------- @@ -47,7 +51,6 @@ class WebsocketClient(object): self.active = False self._disconnect() - #---------------------------------------------------------------------- def sendReq(self, req): # type: (dict)->None """发出请求"""