From 41ee1a0e265b896f8954954c320e2c94c448e228 Mon Sep 17 00:00:00 2001 From: Mobin Ranjbar Date: Sun, 13 Nov 2022 10:44:12 +0330 Subject: [PATCH 1/2] User-defined SSL Options Add User-defined SSL options to prevent SSL verification errors --- pybit/_websocket_stream.py | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/pybit/_websocket_stream.py b/pybit/_websocket_stream.py index 58c4204..a588597 100644 --- a/pybit/_websocket_stream.py +++ b/pybit/_websocket_stream.py @@ -2,6 +2,7 @@ import threading import time import json +import ssl import hmac import logging import re @@ -29,7 +30,7 @@ class _WebSocketManager: def __init__(self, callback_function, ws_name, test, domain="", api_key=None, api_secret=None, ping_interval=20, ping_timeout=10, retries=10, - restart_on_error=True, trace_logging=False): + restart_on_error=True, trace_logging=False, ssl_options=None): self.test = test self.domain = domain @@ -57,6 +58,9 @@ def __init__(self, callback_function, ws_name, self.ping_interval = ping_interval self.ping_timeout = ping_timeout self.retries = retries + + # Set SSL options + self.ssl_options = ssl_options # Other optional data handling settings. self.handle_error = restart_on_error @@ -140,10 +144,17 @@ def resubscribe_to_topics(): ) # Setup the thread running WebSocketApp. - self.wst = threading.Thread(target=lambda: self.ws.run_forever( - ping_interval=self.ping_interval, - ping_timeout=self.ping_timeout - )) + if self.ssl_options is None: + self.wst = threading.Thread(target=lambda: self.ws.run_forever( + ping_interval=self.ping_interval, + ping_timeout=self.ping_timeout + )) + else: + self.wst = threading.Thread(target=lambda: self.ws.run_forever( + sslopt=self.ssl_options, + ping_interval=self.ping_interval, + ping_timeout=self.ping_timeout + )) # Configure as daemon; start. self.wst.daemon = True From 0128773ebf8386f4a60a6ecf76250e6835cdc4ee Mon Sep 17 00:00:00 2001 From: Mobin Ranjbar Date: Sun, 13 Nov 2022 11:09:25 +0330 Subject: [PATCH 2/2] Remove unused import --- pybit/_websocket_stream.py | 1 - 1 file changed, 1 deletion(-) diff --git a/pybit/_websocket_stream.py b/pybit/_websocket_stream.py index a588597..ef0f66f 100644 --- a/pybit/_websocket_stream.py +++ b/pybit/_websocket_stream.py @@ -2,7 +2,6 @@ import threading import time import json -import ssl import hmac import logging import re