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 """发出请求"""