mirror of
https://github.com/aljazceru/bitfinex-api-py.git
synced 2025-12-18 22:34:21 +01:00
Add barebone files for rest section.
This commit is contained in:
@@ -3,6 +3,9 @@ from .websocket import BfxWebsocketClient
|
||||
from enum import Enum
|
||||
|
||||
class Constants(str, Enum):
|
||||
REST_HOST = "https://api.bitfinex.com/v2"
|
||||
PUB_REST_HOST = "https://api-pub.bitfinex.com/v2"
|
||||
|
||||
WSS_HOST = "wss://api.bitfinex.com/ws/2"
|
||||
PUB_WSS_HOST = "wss://api-pub.bitfinex.com/ws/2"
|
||||
|
||||
|
||||
12
bfxapi/rest/BfxRestInterface.py
Normal file
12
bfxapi/rest/BfxRestInterface.py
Normal file
@@ -0,0 +1,12 @@
|
||||
import requests
|
||||
from . import serializers
|
||||
from .typings import PlatformStatus
|
||||
|
||||
class BfxRestInterface(object):
|
||||
def __init__(self, host):
|
||||
self.host = host
|
||||
|
||||
def platform_status(self) -> PlatformStatus:
|
||||
return serializers.PlatformStatus.parse(
|
||||
*requests.get(f"{self.host}/platform/status").json()
|
||||
)
|
||||
1
bfxapi/rest/__init__.py
Normal file
1
bfxapi/rest/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
from .BfxRestInterface import BfxRestInterface
|
||||
6
bfxapi/rest/exceptions.py
Normal file
6
bfxapi/rest/exceptions.py
Normal file
@@ -0,0 +1,6 @@
|
||||
class BfxRestException(Exception):
|
||||
"""
|
||||
Base class for all exceptions defined in bfxapi/rest/exceptions.py.
|
||||
"""
|
||||
|
||||
pass
|
||||
30
bfxapi/rest/serializers.py
Normal file
30
bfxapi/rest/serializers.py
Normal file
@@ -0,0 +1,30 @@
|
||||
from typing import Generic, TypeVar, Iterable, List, Any
|
||||
|
||||
from . import typings
|
||||
|
||||
from .exceptions import BfxRestException
|
||||
|
||||
T = TypeVar("T")
|
||||
|
||||
class _Serializer(Generic[T]):
|
||||
def __init__(self, name: str, labels: List[str]):
|
||||
self.name, self.__labels = name, labels
|
||||
|
||||
def __serialize(self, *args: Any, IGNORE: List[str] = [ "_PLACEHOLDER" ]) -> Iterable[T]:
|
||||
if len(self.__labels) != len(args):
|
||||
raise BfxRestException("<self.__labels> and <*args> arguments should contain the same amount of elements.")
|
||||
|
||||
for index, label in enumerate(self.__labels):
|
||||
if label not in IGNORE:
|
||||
yield label, args[index]
|
||||
|
||||
def parse(self, *values: Any) -> T:
|
||||
return dict(self.__serialize(*values))
|
||||
|
||||
#region Serializers definition for Rest Public Endpoints
|
||||
|
||||
PlatformStatus = _Serializer[typings.PlatformStatus]("PlatformStatus", labels=[
|
||||
"OPERATIVE"
|
||||
])
|
||||
|
||||
#endregion
|
||||
9
bfxapi/rest/typings.py
Normal file
9
bfxapi/rest/typings.py
Normal file
@@ -0,0 +1,9 @@
|
||||
from typing import Type, Tuple, List, Dict, TypedDict, Union, Optional, Any
|
||||
|
||||
#region Type hinting for Rest Public Endpoints
|
||||
|
||||
PlatformStatus = TypedDict("PlatformStatus", {
|
||||
"OPERATIVE": int
|
||||
})
|
||||
|
||||
#endregion
|
||||
@@ -9,7 +9,7 @@ __all__ = [
|
||||
|
||||
class BfxWebsocketException(Exception):
|
||||
"""
|
||||
Base class for all exceptions defined in bfx/websocket/errors.py.
|
||||
Base class for all exceptions defined in bfxapi/websocket/exceptions.py.
|
||||
"""
|
||||
|
||||
pass
|
||||
|
||||
BIN
requirements.txt
BIN
requirements.txt
Binary file not shown.
5
setup.py
5
setup.py
@@ -11,8 +11,13 @@ setup(
|
||||
description="Official Bitfinex Python API",
|
||||
keywords="bitfinex,api,trading",
|
||||
install_requires=[
|
||||
"certifi~=2022.9.24",
|
||||
"charset-normalizer~=2.1.1",
|
||||
"idna~=3.4",
|
||||
"pyee~=9.0.4",
|
||||
"requests~=2.28.1",
|
||||
"typing_extensions~=4.4.0",
|
||||
"urllib3~=1.26.13",
|
||||
"websockets~=10.4",
|
||||
],
|
||||
project_urls={
|
||||
|
||||
Reference in New Issue
Block a user