Remove cid.py and integers.py from bfxapi.utils subpackage. Rename encoder.py file to JSONEncoder.py. Remove IntegerUnderflowError and IntegerOverflowflowError exceptions from bfxapi/exceptions.py.

This commit is contained in:
Davide Casale
2023-02-01 17:17:38 +01:00
parent 05784cc8ec
commit 06dc9e1c0a
8 changed files with 5 additions and 68 deletions

View File

@@ -1,9 +1,7 @@
__all__ = [ __all__ = [
"BfxBaseException", "BfxBaseException",
"LabelerSerializerException", "LabelerSerializerException",
"IntegerUnderflowError",
"IntegerOverflowflowError"
] ]
class BfxBaseException(Exception): class BfxBaseException(Exception):
@@ -18,18 +16,4 @@ class LabelerSerializerException(BfxBaseException):
This exception indicates an error thrown by the _Serializer class in bfxapi/labeler.py. This exception indicates an error thrown by the _Serializer class in bfxapi/labeler.py.
""" """
pass
class IntegerUnderflowError(BfxBaseException):
"""
This error indicates an underflow in one of the integer types defined in bfxapi/utils/integers.py.
"""
pass
class IntegerOverflowflowError(BfxBaseException):
"""
This error indicates an overflow in one of the integer types defined in bfxapi/utils/integers.py.
"""
pass pass

View File

@@ -4,7 +4,7 @@ from http import HTTPStatus
from .enums import Error from .enums import Error
from .exceptions import ResourceNotFound, RequestParametersError, InvalidAuthenticationCredentials, UnknownGenericError from .exceptions import ResourceNotFound, RequestParametersError, InvalidAuthenticationCredentials, UnknownGenericError
from .. utils.encoder import JSONEncoder from ..utils.JSONEncoder import JSONEncoder
class _Requests(object): class _Requests(object):
def __init__(self, host, API_KEY = None, API_SECRET = None): def __init__(self, host, API_KEY = None, API_SECRET = None):

View File

@@ -4,7 +4,7 @@ from dataclasses import dataclass
from .. labeler import _Type from .. labeler import _Type
from .. notification import Notification from .. notification import Notification
from .. utils.encoder import JSON from ..utils.JSONEncoder import JSON
__types__ = [ __types__ = [
"PlatformStatus", "TradingPairTicker", "FundingCurrencyTicker", "PlatformStatus", "TradingPairTicker", "FundingCurrencyTicker",

View File

@@ -1,4 +0,0 @@
import time
def generate_unique_cid(multiplier: int = 1000) -> int:
return int(round(time.time() * multiplier))

View File

@@ -1,43 +0,0 @@
from typing import cast, TypeVar, Union
from .. exceptions import IntegerUnderflowError, IntegerOverflowflowError
__all__ = [ "Int16", "Int32", "Int45", "Int64" ]
T = TypeVar("T")
class _Int(int):
def __new__(cls: T, integer: int) -> T:
assert hasattr(cls, "_BITS"), "_Int must be extended by a class that has a static member _BITS (indicating the number of bits with which to represent the integers)."
bits = cls._BITS - 1
min, max = -(2 ** bits), (2 ** bits) - 1
if integer < min:
raise IntegerUnderflowError(f"Underflow. Cannot store <{integer}> in {cls._BITS} bits integer. The min and max bounds are {min} and {max}.")
if integer > max:
raise IntegerOverflowflowError(f"Overflow. Cannot store <{integer}> in {cls._BITS} bits integer. The min and max bounds are {min} and {max}.")
return cast(T, super().__new__(int, integer))
class Int16(_Int):
_BITS = 16
int16 = Union[Int16, int]
class Int32(_Int):
_BITS = 32
int32 = Union[Int32, int]
class Int45(_Int):
_BITS = 45
int45 = Union[Int45, int]
class Int64(_Int):
_BITS = 64
int64 = Union[Int64, int]

View File

@@ -10,7 +10,7 @@ from ._BfxWebsocketInputs import _BfxWebsocketInputs
from .handlers import Channels, PublicChannelsHandler, AuthenticatedChannelsHandler from .handlers import Channels, PublicChannelsHandler, AuthenticatedChannelsHandler
from .exceptions import WebsocketAuthenticationRequired, InvalidAuthenticationCredentials, EventNotSupported from .exceptions import WebsocketAuthenticationRequired, InvalidAuthenticationCredentials, EventNotSupported
from ..utils.encoder import JSONEncoder from ..utils.JSONEncoder import JSONEncoder
from ..utils.logger import Formatter, CustomLogger from ..utils.logger import Formatter, CustomLogger

View File

@@ -4,7 +4,7 @@ from dataclasses import dataclass
from ..labeler import _Type from ..labeler import _Type
from ..notification import Notification from ..notification import Notification
from .. utils.encoder import JSON from ..utils.JSONEncoder import JSON
__types__ = [ __types__ = [
"TradingPairTicker", "FundingCurrencyTicker", "TradingPairTrade", "TradingPairTicker", "FundingCurrencyTicker", "TradingPairTrade",