From 65318beee970c0a753162b82b8ce374ef723e6ce Mon Sep 17 00:00:00 2001 From: Davide Casale Date: Thu, 4 Apr 2024 16:42:08 +0200 Subject: [PATCH 1/4] Handle unexpected errors in HTTP requests (bfxapi.rest._interface). --- bfxapi/rest/_interface/middleware.py | 28 +++++++++++++++------------- bfxapi/rest/exceptions.py | 4 ++-- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/bfxapi/rest/_interface/middleware.py b/bfxapi/rest/_interface/middleware.py index f2e2b83..92967c1 100644 --- a/bfxapi/rest/_interface/middleware.py +++ b/bfxapi/rest/_interface/middleware.py @@ -3,14 +3,14 @@ import json from datetime import datetime from enum import IntEnum -from typing import TYPE_CHECKING, Any, List, Optional +from typing import TYPE_CHECKING, Any, List, NoReturn, Optional import requests from bfxapi._utils.json_decoder import JSONDecoder from bfxapi._utils.json_encoder import JSONEncoder from bfxapi.exceptions import InvalidCredentialError -from bfxapi.rest.exceptions import RequestParametersError, UnknownGenericError +from bfxapi.rest.exceptions import GenericError, RequestParameterError if TYPE_CHECKING: from requests.sessions import _Params @@ -86,28 +86,30 @@ def post( return data - def __handle_error(self, error: List[Any]) -> None: + def __handle_error(self, error: List[Any]) -> NoReturn: if error[1] == _Error.ERR_PARAMS: - raise RequestParametersError( - "The request was rejected with the following parameter" - f"error: <{error[2]}>" + raise RequestParameterError( + "The request was rejected with the following parameter " + f"error: <{error[2]}>." ) if error[1] == _Error.ERR_AUTH_FAIL: raise InvalidCredentialError( - "Cannot authenticate with given API-KEY and API-SECRET." + "Can't authenticate with given API-KEY and API-SECRET." ) if not error[1] or error[1] == _Error.ERR_UNK or error[1] == _Error.ERR_GENERIC: - raise UnknownGenericError( - "The server replied to the request with a generic error with " - f"the following message: <{error[2]}>." + raise GenericError( + "The request was rejected with the following generic " + f"error: <{error[2]}>." ) + raise RuntimeError( + f"The request was rejected with an unexpected error: <{error}>." + ) + def __get_authentication_headers(self, endpoint: str, data: Optional[str] = None): - assert ( - self.__api_key and self.__api_secret - ), "API-KEY and API-SECRET must be strings." + assert self.__api_key and self.__api_secret nonce = str(round(datetime.now().timestamp() * 1_000_000)) diff --git a/bfxapi/rest/exceptions.py b/bfxapi/rest/exceptions.py index b55bc2a..7bc3c67 100644 --- a/bfxapi/rest/exceptions.py +++ b/bfxapi/rest/exceptions.py @@ -1,9 +1,9 @@ from bfxapi.exceptions import BfxBaseException -class RequestParametersError(BfxBaseException): +class RequestParameterError(BfxBaseException): pass -class UnknownGenericError(BfxBaseException): +class GenericError(BfxBaseException): pass From 089e193780b41a4b60976cce91a21c369e5ae027 Mon Sep 17 00:00:00 2001 From: Davide Casale Date: Thu, 4 Apr 2024 16:43:43 +0200 Subject: [PATCH 2/4] Remove all references to beta versions in README.md. --- README.md | 20 +++----------------- 1 file changed, 3 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index 3f44473..6ee849b 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,7 @@ -# bitfinex-api-py (v3-beta) +# bitfinex-api-py Official implementation of the [Bitfinex APIs (V2)](https://docs.bitfinex.com/docs) for `Python 3.8+`. -> **DISCLAIMER:** \ -Production use of v3.0.0b1 (and all future beta versions) is HIGHLY discouraged. \ -Beta versions should not be used in applications which require user authentication. \ -Provide your API-KEY/API-SECRET, and manage your account and funds at your own risk. - ### Features * Support for 75+ REST endpoints (a list of available endpoints can be found [here](https://docs.bitfinex.com/reference)) @@ -20,13 +15,6 @@ Provide your API-KEY/API-SECRET, and manage your account and funds at your own r python3 -m pip install --pre bitfinex-api-py ``` -### Selecting and installing a specific beta version - -It's also possible to select and install a specific beta version: -```console -python3 -m pip install bitfinex-api-py==3.0.0b1 -``` - --- # Quickstart @@ -305,7 +293,7 @@ All contributions are welcome! :D A guide on how to install and set up `bitfinex-api-py`'s source code can be found [here](#installation-and-setup). \ Before opening any pull requests, please have a look at [Before Opening a PR](#before-opening-a-pr). \ -Contributors must uphold the [Contributor Covenant code of conduct](https://github.com/bitfinexcom/bitfinex-api-py/blob/v3-beta/CODE_OF_CONDUCT.md). +Contributors must uphold the [Contributor Covenant code of conduct](https://github.com/bitfinexcom/bitfinex-api-py/blob/master/CODE_OF_CONDUCT.md). ### Index @@ -323,10 +311,8 @@ A brief guide on how to install and set up the project in your Python 3.8+ envir ### Cloning the repository -The following command will only clone the `v3-beta` branch (excluding all others): - ```console -git clone --branch v3-beta --single-branch https://github.com/bitfinexcom/bitfinex-api-py.git +git clone https://github.com/bitfinexcom/bitfinex-api-py.git ``` ### Installing the dependencies From ba76447c414daea88468aa33a5e60f9faaaecb68 Mon Sep 17 00:00:00 2001 From: Davide Casale Date: Thu, 4 Apr 2024 16:44:05 +0200 Subject: [PATCH 3/4] Upgrade project's 'Development Status' to '5 - Production/Stable'. --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index dcab900..6af03ce 100644 --- a/setup.py +++ b/setup.py @@ -16,7 +16,7 @@ author_email="support@bitfinex.com", license="Apache-2.0", classifiers=[ - "Development Status :: 4 - Beta", + "Development Status :: 5 - Production/Stable", "Intended Audience :: Developers", "Topic :: Software Development :: Build Tools", "License :: OSI Approved :: Apache Software License", From 354aa6250ee7b79804404c13b163c3247ffdff75 Mon Sep 17 00:00:00 2001 From: Davide Casale Date: Thu, 4 Apr 2024 16:44:20 +0200 Subject: [PATCH 4/4] Bump __version__ in file bfxapi/_version.py to v3.0.0. --- bfxapi/_version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bfxapi/_version.py b/bfxapi/_version.py index b6aac9a..528787c 100644 --- a/bfxapi/_version.py +++ b/bfxapi/_version.py @@ -1 +1 @@ -__version__ = "3.0.0b5" +__version__ = "3.0.0"