From 15a2e41e438547a0f9c4547982d771066db62279 Mon Sep 17 00:00:00 2001 From: itsdeka Date: Wed, 8 Feb 2023 11:56:45 +0100 Subject: [PATCH] user info + fixs --- .../endpoints/rest_authenticated_endpoints.py | 3 + bfxapi/rest/serializers.py | 58 +++++++++++++++++++ bfxapi/rest/types.py | 31 ++++++++++ examples/rest/funding_auto_renew.py | 2 +- examples/rest/get_authenticated_data.py | 11 +++- 5 files changed, 102 insertions(+), 3 deletions(-) diff --git a/bfxapi/rest/endpoints/rest_authenticated_endpoints.py b/bfxapi/rest/endpoints/rest_authenticated_endpoints.py index a207673..384a418 100644 --- a/bfxapi/rest/endpoints/rest_authenticated_endpoints.py +++ b/bfxapi/rest/endpoints/rest_authenticated_endpoints.py @@ -11,6 +11,9 @@ from datetime import datetime from ..middleware import Middleware class RestAuthenticatedEndpoints(Middleware): + def get_user_info(self) -> UserInfo: + return serializers.UserInfo.parse(*self._POST(f"auth/r/info/user")) + 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 021211c..a33a04d 100644 --- a/bfxapi/rest/serializers.py +++ b/bfxapi/rest/serializers.py @@ -268,6 +268,64 @@ FxRate = generate_labeler_serializer("FxRate", klass=types.FxRate, labels=[ #region Serializers definition for Rest Authenticated Endpoints +UserInfo = generate_labeler_serializer("UserInfo", klass=types.UserInfo, labels=[ + "id", + "email", + "username", + "mts_account_create", + "verified", + "verification_level", + "_PLACEHOLDER", + "timezone", + "locale", + "company", + "email_verified", + "_PLACEHOLDER", + "_PLACEHOLDER", + "_PLACEHOLDER", + "mts_master_account_create", + "group_id", + "master_account_id", + "inherit_master_account_verification", + "is_group_master", + "group_withdraw_enabled", + "_PLACEHOLDER", + "_PLACEHOLDER", + "_PLACEHOLDER", + "ppt_enabled", + "merchant_enabled", + "competition_enabled", + "two_factors_authentication_modes", + "_PLACEHOLDER", + "_PLACEHOLDER", + "_PLACEHOLDER", + "_PLACEHOLDER", + "_PLACEHOLDER", + "_PLACEHOLDER", + "_PLACEHOLDER", + "is_securities_master", + "_PLACEHOLDER", + "_PLACEHOLDER", + "_PLACEHOLDER", + "securities_enabled", + "allow_disable_ctxswitch", + "_PLACEHOLDER", + "_PLACEHOLDER", + "_PLACEHOLDER", + "_PLACEHOLDER", + "time_last_login", + "_PLACEHOLDER", + "_PLACEHOLDER", + "ctxtswitch_disabled", + "_PLACEHOLDER", + "comp_countries", + "compl_countries_resid", + "_PLACEHOLDER", + "_PLACEHOLDER", + "_PLACEHOLDER", + "is_merchant_enterprise" +]) + Order = generate_labeler_serializer("Order", klass=types.Order, labels=[ "id", "gid", diff --git a/bfxapi/rest/types.py b/bfxapi/rest/types.py index ab41fec..da0f1bc 100644 --- a/bfxapi/rest/types.py +++ b/bfxapi/rest/types.py @@ -197,6 +197,37 @@ class FxRate(_Type): #region Type hinting for Rest Authenticated Endpoints +@dataclass +class UserInfo(_Type): + id: int + email: str + username: str + mts_account_create: int + verified: int + verification_level: int + timezone: str + locale: str + company: str + email_verified: int + mts_master_account_create: int + group_id: int + master_account_id: int + inherit_master_account_verification: int + is_group_master: int + group_withdraw_enabled: int + ppt_enabled: int + merchant_enabled: int + competition_enabled: int + two_factors_authentication_modes: List[str] + is_securities_master: int + securities_enabled: int + allow_disable_ctxswitch: int + ctxtswitch_disabled: int + time_last_login: int + comp_countries: List[str] + compl_countries_resid: List[str] + is_merchant_enterprise: int + @dataclass class Order(_Type): id: int diff --git a/examples/rest/funding_auto_renew.py b/examples/rest/funding_auto_renew.py index c892ce3..11ee7ca 100644 --- a/examples/rest/funding_auto_renew.py +++ b/examples/rest/funding_auto_renew.py @@ -14,7 +14,7 @@ notification = bfx.rest.auth.toggle_auto_renew( status=True, currency="USD", amount="150", - rate="0", + rate="0", # FRR period=2 ) diff --git a/examples/rest/get_authenticated_data.py b/examples/rest/get_authenticated_data.py index 2ff1de6..f398773 100644 --- a/examples/rest/get_authenticated_data.py +++ b/examples/rest/get_authenticated_data.py @@ -13,6 +13,12 @@ bfx = Client( now = int(round(time.time() * 1000)) + +def log_user_info(): + user_info = bfx.rest.auth.get_user_info() + print(user_info) + + def log_wallets(): wallets = bfx.rest.auth.get_wallets() print("Wallets:") @@ -38,14 +44,14 @@ def log_positions(): def log_trades(): - trades = bfx.rest.auth.get_trades(symbol='tBTCUSD', start=0, end=now) + trades = bfx.rest.auth.get_trades_history(symbol='tBTCUSD', start=0, end=now) print("Trades:") [print(t) for t in trades] def log_order_trades(): order_id = 82406909127 - trades = bfx.rest.auth.get_order_trades(symbol='tBTCUSD', order_id=order_id) + trades = bfx.rest.auth.get_order_trades(symbol='tBTCUSD', id=order_id) print("Trade orders:") [print(t) for t in trades] @@ -96,6 +102,7 @@ def log_margin_info(): print(f"Base margin info {base_margin_info}") def run(): + log_user_info() log_wallets() log_orders() log_orders_history()