From 48583786f7338e7e8c1711f296bb37859a514179 Mon Sep 17 00:00:00 2001 From: itsdeka Date: Wed, 8 Feb 2023 12:39:51 +0100 Subject: [PATCH] login history + balance available --- .../endpoints/rest_authenticated_endpoints.py | 9 +++++++++ bfxapi/rest/serializers.py | 15 +++++++++++++++ bfxapi/rest/types.py | 11 +++++++++++ examples/rest/get_authenticated_data.py | 5 +++++ 4 files changed, 40 insertions(+) diff --git a/bfxapi/rest/endpoints/rest_authenticated_endpoints.py b/bfxapi/rest/endpoints/rest_authenticated_endpoints.py index 384a418..4307bc0 100644 --- a/bfxapi/rest/endpoints/rest_authenticated_endpoints.py +++ b/bfxapi/rest/endpoints/rest_authenticated_endpoints.py @@ -14,6 +14,15 @@ class RestAuthenticatedEndpoints(Middleware): def get_user_info(self) -> UserInfo: return serializers.UserInfo.parse(*self._POST(f"auth/r/info/user")) + def get_login_history(self) -> LoginHistory: + return [ serializers.LoginHistory.parse(*sub_data) for sub_data in self._POST("auth/r/logins/hist") ] + + def get_balance_available_for_orders_or_offers(self, symbol: str, type: str, dir: Optional[int] = None, rate: Optional[str] = None, lev: Optional[str] = None) -> BalanceAvailable: + return serializers.BalanceAvailable.parse(*self._POST("auth/calc/order/avail", body={ + "symbol": symbol, "type": type, "dir": dir, + "rate": rate, "lev": lev + })) + def get_wallets(self) -> List[Wallet]: return [ serializers.Wallet.parse(*sub_data) for sub_data in self._POST("auth/r/wallets") ] diff --git a/bfxapi/rest/serializers.py b/bfxapi/rest/serializers.py index a33a04d..43943ff 100644 --- a/bfxapi/rest/serializers.py +++ b/bfxapi/rest/serializers.py @@ -326,6 +326,21 @@ UserInfo = generate_labeler_serializer("UserInfo", klass=types.UserInfo, labels= "is_merchant_enterprise" ]) +LoginHistory = generate_labeler_serializer("LoginHistory", klass=types.LoginHistory, labels=[ + "id", + "_PLACEHOLDER", + "time", + "_PLACEHOLDER", + "ip", + "_PLACEHOLDER", + "_PLACEHOLDER", + "extra_info" +]) + +BalanceAvailable = generate_labeler_serializer("BalanceAvailable", klass=types.BalanceAvailable, labels=[ + "amount" +]) + Order = generate_labeler_serializer("Order", klass=types.Order, labels=[ "id", "gid", diff --git a/bfxapi/rest/types.py b/bfxapi/rest/types.py index da0f1bc..eee3c30 100644 --- a/bfxapi/rest/types.py +++ b/bfxapi/rest/types.py @@ -228,6 +228,17 @@ class UserInfo(_Type): compl_countries_resid: List[str] is_merchant_enterprise: int +@dataclass +class LoginHistory(_Type): + id: int + time: int + ip: str + extra_info: JSON + +@dataclass +class BalanceAvailable(_Type): + amount: float + @dataclass class Order(_Type): id: int diff --git a/examples/rest/get_authenticated_data.py b/examples/rest/get_authenticated_data.py index f398773..ada724a 100644 --- a/examples/rest/get_authenticated_data.py +++ b/examples/rest/get_authenticated_data.py @@ -19,6 +19,11 @@ def log_user_info(): print(user_info) +def log_login_history(): + login_history = bfx.rest.auth.get_login_history() + print(login_history) + + def log_wallets(): wallets = bfx.rest.auth.get_wallets() print("Wallets:")