From 455a1851a7e10766e3ab78a73a59f1616ea1ac92 Mon Sep 17 00:00:00 2001 From: qqqlyx Date: Wed, 3 Apr 2019 16:31:53 +0800 Subject: [PATCH 1/2] [Add] ping_interval MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 增加了一个变量,用来控制websocket_client中ping的时间间隔。 --- vnpy/api/websocket/websocket_client.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/vnpy/api/websocket/websocket_client.py b/vnpy/api/websocket/websocket_client.py index 61541594..563cc64f 100644 --- a/vnpy/api/websocket/websocket_client.py +++ b/vnpy/api/websocket/websocket_client.py @@ -50,9 +50,10 @@ class WebsocketClient(object): self._last_sent_text = None self._last_received_text = None - def init(self, host: str, proxy_host: str = "", proxy_port: int = 0): + def init(self, host: str, proxy_host: str = "", proxy_port: int = 0, ping_interval: int = 60): """""" self.host = host + self.ping_interval = ping_interval # seconds if proxy_host and proxy_port: self.proxy_host = proxy_host @@ -202,7 +203,7 @@ class WebsocketClient(object): et, ev, tb = sys.exc_info() self.on_error(et, ev, tb) self._reconnect() - for i in range(60): + for i in range(self.ping_interval): if not self._active: break sleep(1) From b8c648b432f373df772594ac9550d8920a7a68d2 Mon Sep 17 00:00:00 2001 From: qqqlyx Date: Wed, 3 Apr 2019 17:46:48 +0800 Subject: [PATCH 2/2] update --- vnpy/api/websocket/websocket_client.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/vnpy/api/websocket/websocket_client.py b/vnpy/api/websocket/websocket_client.py index 563cc64f..185ed046 100644 --- a/vnpy/api/websocket/websocket_client.py +++ b/vnpy/api/websocket/websocket_client.py @@ -45,13 +45,16 @@ class WebsocketClient(object): self.proxy_host = None self.proxy_port = None + self.ping_interval = 60 # seconds # For debugging self._last_sent_text = None self._last_received_text = None def init(self, host: str, proxy_host: str = "", proxy_port: int = 0, ping_interval: int = 60): - """""" + """ + :param ping_interval: unit: seconds, type: int + """ self.host = host self.ping_interval = ping_interval # seconds