Organize rest sub-package. Create new endpoints and middleware sub-packages. Rename class Requests to Middleware.

This commit is contained in:
Davide Casale
2023-02-07 18:31:02 +01:00
parent 0a9384e670
commit 2d01261182
9 changed files with 44 additions and 30 deletions

View File

@@ -1,13 +0,0 @@
from typing import Optional
from ._RestPublicEndpoints import _RestPublicEndpoints
from ._RestAuthenticatedEndpoints import _RestAuthenticatedEndpoints
class BfxRestInterface(object):
VERSION = 2
def __init__(self, host: str, API_KEY: Optional[str] = None, API_SECRET: Optional[str] = None):
self.public = _RestPublicEndpoints(host=host)
self.auth = _RestAuthenticatedEndpoints(host=host, API_KEY=API_KEY, API_SECRET=API_SECRET)

View File

@@ -1 +1,3 @@
from .BfxRestInterface import BfxRestInterface
from .endpoints import BfxRestInterface, RestPublicEndpoints, RestAuthenticatedEndpoints
NAME = "rest"

View File

@@ -0,0 +1,5 @@
from .bfx_rest_interface import BfxRestInterface
from .rest_public_endpoints import RestPublicEndpoints
from .rest_authenticated_endpoints import RestAuthenticatedEndpoints
NAME = "endpoints"

View File

@@ -0,0 +1,13 @@
from typing import Optional
from .rest_public_endpoints import RestPublicEndpoints
from .rest_authenticated_endpoints import RestAuthenticatedEndpoints
class BfxRestInterface(object):
VERSION = 2
def __init__(self, host: str, API_KEY: Optional[str] = None, API_SECRET: Optional[str] = None):
self.public = RestPublicEndpoints(host=host)
self.auth = RestAuthenticatedEndpoints(host=host, API_KEY=API_KEY, API_SECRET=API_SECRET)

View File

@@ -1,16 +1,16 @@
from typing import List, Union, Literal, Optional, Any, cast
from typing import List, Union, Literal, Optional
from .types import *
from ..types import *
from . import serializers
from .. import serializers
from .enums import Config, Sort, OrderType, FundingOfferType
from ..enums import Sort, OrderType, FundingOfferType
from decimal import Decimal
from datetime import datetime
from ._Requests import _Requests
from ..middleware import Middleware
class _RestAuthenticatedEndpoints(_Requests):
class RestAuthenticatedEndpoints(Middleware):
def get_wallets(self) -> List[Wallet]:
return [ serializers.Wallet.parse(*sub_data) for sub_data in self._POST("auth/r/wallets") ]

View File

@@ -1,15 +1,15 @@
from typing import List, Union, Literal, Optional, Any, cast
from .types import *
from ..types import *
from . import serializers
from .. import serializers
from .enums import Config, Sort
from ..enums import Config, Sort
from decimal import Decimal
from ._Requests import _Requests
from ..middleware import Middleware
class _RestPublicEndpoints(_Requests):
class RestPublicEndpoints(Middleware):
def conf(self, config: Config) -> Any:
return self._GET(f"conf/{config}")[0]

View File

@@ -0,0 +1,3 @@
from .middleware import Middleware
NAME = "middleware"

View File

@@ -3,15 +3,15 @@ import time, hmac, hashlib, json, requests
from typing import TYPE_CHECKING, Optional, Any
from http import HTTPStatus
from .enums import Error
from .exceptions import ResourceNotFound, RequestParametersError, InvalidAuthenticationCredentials, UnknownGenericError
from ..enums import Error
from ..exceptions import ResourceNotFound, RequestParametersError, InvalidAuthenticationCredentials, UnknownGenericError
from ..utils.JSONEncoder import JSONEncoder
from ...utils.JSONEncoder import JSONEncoder
if TYPE_CHECKING:
from requests.sessions import _Params
class _Requests(object):
class Middleware(object):
def __init__(self, host: str, API_KEY: Optional[str] = None, API_SECRET: Optional[str] = None):
self.host, self.API_KEY, self.API_SECRET = host, API_KEY, API_SECRET

View File

@@ -3,7 +3,11 @@ from distutils.core import setup
setup(
name="bitfinex-api-py",
version="3.0.0",
packages=[ "bfxapi", "bfxapi.websocket", "bfxapi.rest", "bfxapi.utils" ],
packages=[
"bfxapi", "bfxapi.utils",
"bfxapi.websocket",
"bfxapi.rest", "bfxapi.rest.endpoints", "bfxapi.rest.middleware",
],
url="https://github.com/bitfinexcom/bitfinex-api-py",
license="OSI Approved :: Apache Software License",
author="Bitfinex",