Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add a websocket callback: on_disconnected() #158

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion binance/websocket/binance_socket_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ def __init__(
on_error=None,
on_ping=None,
on_pong=None,
on_disconnected=None,
logger=None,
proxies: Optional[dict] = None,
):
Expand All @@ -35,6 +36,7 @@ def __init__(
self.on_ping = on_ping
self.on_pong = on_pong
self.on_error = on_error
self.on_disconnected = on_disconnected
self.proxies = proxies

self._proxy_params = parse_proxies(proxies) if proxies else {}
Expand Down Expand Up @@ -69,9 +71,10 @@ def read_data(self):
except WebSocketException as e:
if isinstance(e, WebSocketConnectionClosedException):
self.logger.error("Lost websocket connection")
self._callback(self.on_disconnected)
else:
self.logger.error("Websocket exception: {}".format(e))
raise e
raise e
except Exception as e:
self.logger.error("Exception in read_data: {}".format(e))
raise e
Expand Down
2 changes: 2 additions & 0 deletions binance/websocket/cm_futures/websocket_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ def __init__(
on_error=None,
on_ping=None,
on_pong=None,
on_disconnected=None,
is_combined=False,
proxies: Optional[dict] = None,
):
Expand All @@ -28,6 +29,7 @@ def __init__(
on_error=on_error,
on_ping=on_ping,
on_pong=on_pong,
on_disconnected=on_disconnected,
proxies=proxies,
)

Expand Down
2 changes: 2 additions & 0 deletions binance/websocket/um_futures/websocket_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ def __init__(
on_error=None,
on_ping=None,
on_pong=None,
on_disconnected=None,
is_combined=False,
proxies: Optional[dict] = None,
):
Expand All @@ -28,6 +29,7 @@ def __init__(
on_error=on_error,
on_ping=on_ping,
on_pong=on_pong,
on_disconnected=on_disconnected,
proxies=proxies,
)

Expand Down
4 changes: 4 additions & 0 deletions binance/websocket/websocket_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ def __init__(
on_error=None,
on_ping=None,
on_pong=None,
on_disconnected=None,
logger=None,
proxies: Optional[dict] = None,
):
Expand All @@ -34,6 +35,7 @@ def __init__(
on_error,
on_ping,
on_pong,
on_disconnected,
logger,
proxies,
)
Expand All @@ -51,6 +53,7 @@ def _initialize_socket(
on_error,
on_ping,
on_pong,
on_disconnected,
logger,
proxies,
):
Expand All @@ -62,6 +65,7 @@ def _initialize_socket(
on_error=on_error,
on_ping=on_ping,
on_pong=on_pong,
on_disconnected=on_disconnected,
logger=logger,
proxies=proxies,
)
Expand Down