Skip to content

Commit 433eef8

Browse files
author
Sam McHardy
committed
Merge branch 'feature/websocket_timeout' into develop
2 parents 3acf9a0 + 49dc10c commit 433eef8

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

binance/websockets.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,15 @@ class BinanceSocketManager(threading.Thread):
6666
WEBSOCKET_DEPTH_10 = '10'
6767
WEBSOCKET_DEPTH_20 = '20'
6868

69-
_user_timeout = 30 * 60 # 30 minutes
69+
DEFAULT_USER_TIMEOUT = 30 * 60 # 30 minutes
7070

71-
def __init__(self, client):
71+
def __init__(self, client, user_timeout=DEFAULT_USER_TIMEOUT):
7272
"""Initialise the BinanceSocketManager
7373
7474
:param client: Binance API client
7575
:type client: binance.Client
76+
:param user_timeout: Custom websocket timeout
77+
:type user_timeout: int
7678
7779
"""
7880
threading.Thread.__init__(self)
@@ -81,6 +83,7 @@ def __init__(self, client):
8183
self._user_listen_key = None
8284
self._user_callback = None
8385
self._client = client
86+
self._user_timeout = user_timeout
8487

8588
def _start_socket(self, path, callback, prefix='ws/'):
8689
if path in self._conns:

docs/websockets.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,13 @@ A callback to process messages would take the format
3737
print(msg)
3838
# do something
3939
40+
Set a custom timeout for the websocket connection
41+
42+
.. code:: python
43+
44+
# set a timeout of 60 seconds
45+
bm = BinanceSocketManager(client, user_timeout=60)
46+
4047
4148
Websocket Errors
4249
----------------

0 commit comments

Comments
 (0)