From bb03a096e3d9f830486f7ce619c6c70e0889e8fe Mon Sep 17 00:00:00 2001 From: Franco Zanuso Date: Sun, 12 Nov 2023 20:29:45 +0000 Subject: [PATCH] add support for python >= 3.8 --- requirements.txt | 2 +- setup.py | 4 ++-- src/pyRofex/__init__.py | 4 ++-- src/pyRofex/clients/websocket_rfx.py | 15 ++++++++------- src/pyRofex/service.py | 14 +++++++------- 5 files changed, 20 insertions(+), 19 deletions(-) diff --git a/requirements.txt b/requirements.txt index 71911f7..f0ef099 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ requests>=2.20.0 simplejson>=3.10.0 enum34>=1.1.6 -websocket-client>=0.54.0,<0.58.0 \ No newline at end of file +websocket-client>=1.6.4 \ No newline at end of file diff --git a/setup.py b/setup.py index 5ce764a..e02b51e 100644 --- a/setup.py +++ b/setup.py @@ -5,7 +5,7 @@ setuptools.setup( name="pyRofex", - version="0.5.0rc1", + version="0.5.0", author="Franco Zanuso", author_email="francozanuso89@gmail.com", description="Python connector for ROFEX's Rest and Websocket APIs.", @@ -18,7 +18,7 @@ 'requests>=2.20.0', 'simplejson>=3.10.0', 'enum34>=1.1.6', - 'websocket-client>=0.54.0,<0.58.0', + 'websocket-client>=1.6.4', ], classifiers=[ "Programming Language :: Python :: 3", diff --git a/src/pyRofex/__init__.py b/src/pyRofex/__init__.py index 9ab6c57..e729f69 100644 --- a/src/pyRofex/__init__.py +++ b/src/pyRofex/__init__.py @@ -2,7 +2,7 @@ """ pyRofex: Python connector for ROFEX Rest and Websocket APIs. - This modules expose functions and enumerations of the library. + This module expose functions and enumerations of the library. """ from .service import initialize from .service import set_default_environment @@ -46,4 +46,4 @@ from .components.enums import Side from .components.enums import TimeInForce -__version__ = "0.5.0rc1" +__version__ = "0.5.0" diff --git a/src/pyRofex/clients/websocket_rfx.py b/src/pyRofex/clients/websocket_rfx.py index 09970d3..80a170f 100644 --- a/src/pyRofex/clients/websocket_rfx.py +++ b/src/pyRofex/clients/websocket_rfx.py @@ -6,7 +6,7 @@ """ import threading import time -import ssl +import logging import websocket import simplejson @@ -149,7 +149,7 @@ def connect(self): if self.ws_connection.sock is None or not self.ws_connection.sock.connected: self.on_exception(ApiException("Connection could not be established.")) - def on_message(self, message): + def on_message(self, ws, message): """ Called when a new message is received through the connection. :param message: message received. @@ -186,7 +186,7 @@ def on_message(self, message): except Exception as e: self.on_exception(e) - def on_error(self, exception): + def on_error(self, ws, exception): """ Called when an error occurred within the connection. :param exception: exception raised. @@ -204,13 +204,14 @@ def on_exception(self, exception): if self.exception_handler is not None: self.exception_handler(exception) - def on_close(self): - """ Called when the connection was closed. + def on_close(self, ws, close_status_code, close_msg): + """ Called when the connection is closed. """ + logging.log(logging.INFO, f"connection closed. code: {close_status_code}. message: {close_msg}") self.connected = False - def on_open(self): - """ Called when the connection was opened. + def on_open(self, ws): + """ Called when the connection is opened. """ self.connected = True diff --git a/src/pyRofex/service.py b/src/pyRofex/service.py index d9882b0..3e93d79 100644 --- a/src/pyRofex/service.py +++ b/src/pyRofex/service.py @@ -4,8 +4,8 @@ All the library exposed functionality """ -import warnings -from inspect import getargspec +import logging +from inspect import getfullargspec from .clients.rest_rfx import RestClient from .clients.websocket_rfx import WebSocketClient @@ -535,7 +535,7 @@ def init_websocket_connection(market_data_handler=None, # Gets the client for the environment client = globals.environment_config[environment]["ws_client"] - # Checks handlers and adds the them into the client. + # Checks handlers and adds them into the client. if market_data_handler is not None: _validate_handler(market_data_handler) client.add_market_data_handler(market_data_handler) @@ -549,7 +549,7 @@ def init_websocket_connection(market_data_handler=None, client.add_error_handler(error_handler) if exception_handler is not None: - _validate_handler(error_handler) + _validate_handler(exception_handler) client.set_exception_handler(exception_handler) # Initiates the connection with the Websocket API @@ -964,9 +964,9 @@ def _validate_handler(handler): raise ApiException("Handler '{handler}' is not callable.".format(handler=handler)) # Checks if function can receive an argument - fun_arg_spec = getargspec(handler) + fun_arg_spec = getfullargspec(handler) if not fun_arg_spec.args and not fun_arg_spec.varargs: - print("Handler '{handler}' can't receive an argument.".format(handler=handler)) + logging.error("Handler '{handler}' can't receive an argument.".format(handler=handler)) def _validate_market_data_entries(entries): @@ -984,6 +984,6 @@ def _validate_market_data_entries(entries): else: for entry in entries: if not isinstance(entry, MarketDataEntry): - print("WARNING: Market Data Entry not defined: " + str(entry)) + logging.warn("WARNING: Market Data Entry not defined: " + str(entry)) return entries