diff --git a/bfxapi/rest/_RestAuthenticatedEndpoints.py b/bfxapi/rest/_RestAuthenticatedEndpoints.py index a464b8e..61ee64d 100644 --- a/bfxapi/rest/_RestAuthenticatedEndpoints.py +++ b/bfxapi/rest/_RestAuthenticatedEndpoints.py @@ -148,6 +148,25 @@ class _RestAuthenticatedEndpoints(_Requests): return [ serializers.FundingOffer.parse(*sub_data) for sub_data in self._POST(endpoint, data=data) ] + def get_funding_loans(self, symbol: Optional[str] = None) -> List[FundingLoan]: + if symbol == None: + endpoint = "auth/r/funding/loans" + else: endpoint = f"auth/r/funding/loans/{symbol}" + + return [ serializers.FundingLoan.parse(*sub_data) for sub_data in self._POST(endpoint) ] + + def get_funding_loans_history(self, symbol: Optional[str] = None, start: Optional[str] = None, end: Optional[str] = None, limit: Optional[int] = None) -> List[FundingLoan]: + if symbol == None: + endpoint = "auth/r/funding/loans/hist" + else: endpoint = f"auth/r/funding/loans/{symbol}/hist" + + data = { + "start": start, "end": end, + "limit": limit + } + + return [ serializers.FundingLoan.parse(*sub_data) for sub_data in self._POST(endpoint, data=data) ] + def get_funding_credits(self, symbol: Optional[str] = None) -> List[FundingCredit]: if symbol == None: endpoint = "auth/r/funding/credits" diff --git a/bfxapi/rest/serializers.py b/bfxapi/rest/serializers.py index a6cf582..44296d9 100644 --- a/bfxapi/rest/serializers.py +++ b/bfxapi/rest/serializers.py @@ -382,6 +382,31 @@ Ledger = generate_labeler_serializer("Ledger", klass=types.Ledger, labels=[ "description" ]) +FundingLoan = generate_labeler_serializer("FundingLoan", klass=types.FundingLoan, labels=[ + "id", + "symbol", + "side", + "mts_create", + "mts_update", + "amount", + "flags", + "status", + "_PLACEHOLDER", + "_PLACEHOLDER", + "_PLACEHOLDER", + "rate", + "period", + "mts_opening", + "mts_last_payout", + "notify", + "hidden", + "_PLACEHOLDER", + "renew", + "rate_real", + "no_close" +]) + + FundingCredit = generate_labeler_serializer("FundingCredit", klass=types.FundingCredit, labels=[ "id", "symbol", diff --git a/bfxapi/rest/types.py b/bfxapi/rest/types.py index 4850404..58ce507 100644 --- a/bfxapi/rest/types.py +++ b/bfxapi/rest/types.py @@ -306,6 +306,26 @@ class Ledger(_Type): balance: float description: str +@dataclass +class FundingLoan(_Type): + id: int + symbol: str + side: int + mts_create: int + mts_update: int + amount: float + flags: int + status: str + rate: float + period: int + mts_opening: int + mts_last_payout: int + notify: int + hidden: int + renew: int + rate_real: float + no_close: int + @dataclass class FundingCredit(_Type): id: int diff --git a/examples/rest/get_authenticated_data.py b/examples/rest/get_authenticated_data.py index 4af5165..2ff1de6 100644 --- a/examples/rest/get_authenticated_data.py +++ b/examples/rest/get_authenticated_data.py @@ -69,7 +69,7 @@ def log_funding_loans(): def log_funding_loans_history(): - loans = bfx.rest.auth.get_funding_loan_history(symbol='fUSD', start=0, end=now) + loans = bfx.rest.auth.get_funding_loans_history(symbol='fUSD', start=0, end=now) print("Funding loan history:") [print(l) for l in loans]