From 01c8192d10de65cd32f27eec7280241fa827f556 Mon Sep 17 00:00:00 2001 From: itsdeka Date: Tue, 24 Jan 2023 12:49:01 +0100 Subject: [PATCH] fx rate --- bfxapi/rest/BfxRestInterface.py | 3 +++ bfxapi/rest/serializers.py | 4 ++++ bfxapi/rest/types.py | 4 ++++ examples/rest/extra_calcs.py | 8 ++++++-- 4 files changed, 17 insertions(+), 2 deletions(-) diff --git a/bfxapi/rest/BfxRestInterface.py b/bfxapi/rest/BfxRestInterface.py index 3dc559f..4e63aba 100644 --- a/bfxapi/rest/BfxRestInterface.py +++ b/bfxapi/rest/BfxRestInterface.py @@ -283,6 +283,9 @@ class _RestPublicEndpoints(_Requests): return serializers.FundingMarketAveragePrice.parse(*self._POST("calc/trade/avg", data=data)) + def get_fx_rate(self, ccy1: str, ccy2: str) -> FxRate: + return serializers.FxRate.parse(*self._POST("calc/fx", data={ "ccy1": ccy1, "ccy2": ccy2 })) + class _RestAuthenticatedEndpoints(_Requests): def get_wallets(self) -> List[Wallet]: return [ serializers.Wallet.parse(*subdata) for subdata in self._POST("auth/r/wallets") ] diff --git a/bfxapi/rest/serializers.py b/bfxapi/rest/serializers.py index 822e4cf..3a69c53 100644 --- a/bfxapi/rest/serializers.py +++ b/bfxapi/rest/serializers.py @@ -241,6 +241,10 @@ FundingMarketAveragePrice = generate_labeler_serializer("FundingMarketAveragePri "AMOUNT" ]) +FxRate = generate_labeler_serializer("FxRate", klass=types.FxRate, labels=[ + "CURRENT_RATE" +]) + #endregion #region Serializers definition for Rest Authenticated Endpoints diff --git a/bfxapi/rest/types.py b/bfxapi/rest/types.py index c0a2611..4b04661 100644 --- a/bfxapi/rest/types.py +++ b/bfxapi/rest/types.py @@ -191,6 +191,10 @@ class FundingMarketAveragePrice(_Type): RATE_AVG: float AMOUNT: float +@dataclass +class FxRate(_Type): + CURRENT_RATE: float + #endregion #region Type hinting for Rest Authenticated Endpoints diff --git a/examples/rest/extra_calcs.py b/examples/rest/extra_calcs.py index cbda41c..2603cd8 100644 --- a/examples/rest/extra_calcs.py +++ b/examples/rest/extra_calcs.py @@ -12,7 +12,7 @@ t_symbol_response = bfx.rest.public.get_trading_market_average_price( price_limit="20000.5" ) -print(t_symbol_response) +print(t_symbol_response.PRICE_AVG) f_symbol_response = bfx.rest.public.get_funding_market_average_price( symbol="fUSD", @@ -21,4 +21,8 @@ f_symbol_response = bfx.rest.public.get_funding_market_average_price( rate_limit="0.00015" ) -print(f_symbol_response) \ No newline at end of file +print(f_symbol_response.RATE_AVG) + +fx_rate = bfx.rest.public.get_fx_rate(ccy1="USD", ccy2="EUR") + +print(fx_rate.CURRENT_RATE) \ No newline at end of file