Add get_funding_loans and get_funding_loans_history endpoints to _RestAuthenticatedEndpoints.py.

This commit is contained in:
Davide Casale
2023-01-27 17:23:41 +01:00
parent 17fc29d4fa
commit 2fc31db7a3
4 changed files with 65 additions and 1 deletions

View File

@@ -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"

View File

@@ -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",

View File

@@ -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

View File

@@ -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]