Skip to content

fix websocket #142

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
30 changes: 17 additions & 13 deletions huobi/connection/impl/websocket_manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,29 @@
websocket_connection_handler = dict()


def on_message(original_connection, message):
def on_message(original_connection, message, *args, **kwargs):
websocket_connection = websocket_connection_handler[original_connection]
websocket_connection.on_message(message)
if websocket_connection and hasattr(websocket_connection, "on_message"):
websocket_connection.on_message(message)
return


def on_error(original_connection, error):
def on_error(original_connection, error, *args, **kwargs):
websocket_connection = websocket_connection_handler[original_connection]
websocket_connection.on_failure(error)
if websocket_connection and hasattr(websocket_connection, "on_failure"):
websocket_connection.on_failure(error)


def on_close(original_connection):
def on_close(original_connection, *args, **kwargs):
websocket_connection = websocket_connection_handler[original_connection]
websocket_connection.on_close()
if websocket_connection and hasattr(websocket_connection, "on_close"):
websocket_connection.on_close()


def on_open(original_connection):
def on_open(original_connection, *args, **kwargs):
websocket_connection = websocket_connection_handler[original_connection]
websocket_connection.on_open(original_connection)
if websocket_connection and hasattr(websocket_connection, "on_open"):
websocket_connection.on_open(original_connection)


connection_id = 0
Expand All @@ -42,9 +46,9 @@ def websocket_func(*args):
try:
websocket_manage = args[0]
websocket_manage.original_connection = websocket.WebSocketApp(websocket_manage.url,
on_message=on_message,
on_error=on_error,
on_close=on_close)
on_message=on_message,
on_error=on_error,
on_close=on_close)
global websocket_connection_handler
websocket_connection_handler[websocket_manage.original_connection] = websocket_manage
websocket_manage.logger.info("[Sub][" + str(websocket_manage.id) + "] Connecting...")
Expand Down Expand Up @@ -137,7 +141,7 @@ def on_open(self, original_connection):
elif self.request.api_version == ApiVersion.VERSION_V2:
builder = UrlParamsBuilder()
create_signature_v2(self.__api_key, self.__secret_key,
"GET", self.url, builder)
"GET", self.url, builder)
self.send(builder.build_url_to_json())
else:
self.on_error("api version for create the signature fill failed")
Expand Down Expand Up @@ -249,7 +253,7 @@ def __on_receive(self, dict_data):
self.request.update_callback(res)
except Exception as e:
self.on_error("Process error: " + str(e)
+ " You should capture the exception in your error handler")
+ " You should capture the exception in your error handler")

# websocket request will close the connection after receive
if self.request.auto_close:
Expand Down