mirror of
https://github.com/aljazceru/bitfinex-api-py.git
synced 2025-12-19 14:54:21 +01:00
Drop modules bfxapi.enums, bfxapi.rest.enums and bfxapi.websocket.enums.
This commit is contained in:
@@ -1,10 +1,11 @@
|
||||
from typing import TYPE_CHECKING, Optional, Any
|
||||
|
||||
from enum import Enum
|
||||
|
||||
from http import HTTPStatus
|
||||
|
||||
import time, hmac, hashlib, json, requests
|
||||
|
||||
from ..enums import Error
|
||||
from ..exceptions import ResourceNotFound, RequestParametersError, InvalidCredentialError, UnknownGenericError
|
||||
from ..._utils.json_encoder import JSONEncoder
|
||||
from ..._utils.json_decoder import JSONDecoder
|
||||
@@ -12,6 +13,12 @@ from ..._utils.json_decoder import JSONDecoder
|
||||
if TYPE_CHECKING:
|
||||
from requests.sessions import _Params
|
||||
|
||||
class _Error(Enum):
|
||||
ERR_UNK = 10000
|
||||
ERR_GENERIC = 10001
|
||||
ERR_PARAMS = 10020
|
||||
ERR_AUTH_FAIL = 10100
|
||||
|
||||
class Middleware:
|
||||
TIMEOUT = 30
|
||||
|
||||
@@ -53,11 +60,11 @@ class Middleware:
|
||||
data = response.json(cls=JSONDecoder)
|
||||
|
||||
if len(data) and data[0] == "error":
|
||||
if data[1] == Error.ERR_PARAMS:
|
||||
if data[1] == _Error.ERR_PARAMS:
|
||||
raise RequestParametersError("The request was rejected with the " \
|
||||
f"following parameter error: <{data[2]}>")
|
||||
|
||||
if data[1] is None or data[1] == Error.ERR_UNK or data[1] == Error.ERR_GENERIC:
|
||||
if data[1] is None or data[1] == _Error.ERR_UNK or data[1] == _Error.ERR_GENERIC:
|
||||
raise UnknownGenericError("The server replied to the request with " \
|
||||
f"a generic error with message: <{data[2]}>.")
|
||||
|
||||
@@ -86,14 +93,14 @@ class Middleware:
|
||||
data = response.json(cls=JSONDecoder)
|
||||
|
||||
if isinstance(data, list) and len(data) and data[0] == "error":
|
||||
if data[1] == Error.ERR_PARAMS:
|
||||
if data[1] == _Error.ERR_PARAMS:
|
||||
raise RequestParametersError("The request was rejected with the " \
|
||||
f"following parameter error: <{data[2]}>")
|
||||
|
||||
if data[1] == Error.ERR_AUTH_FAIL:
|
||||
if data[1] == _Error.ERR_AUTH_FAIL:
|
||||
raise InvalidCredentialError("Cannot authenticate with given API-KEY and API-SECRET.")
|
||||
|
||||
if data[1] is None or data[1] == Error.ERR_UNK or data[1] == Error.ERR_GENERIC:
|
||||
if data[1] is None or data[1] == _Error.ERR_UNK or data[1] == _Error.ERR_GENERIC:
|
||||
raise UnknownGenericError("The server replied to the request with " \
|
||||
f"a generic error with message: <{data[2]}>.")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user