From 3c377928b277120e85f511db13b8f59cee65bff0 Mon Sep 17 00:00:00 2001 From: Davide Casale Date: Sun, 12 Feb 2023 21:41:33 +0100 Subject: [PATCH] fix errors merchant Co-Authored-By: itsdeka --- bfxapi/rest/endpoints/rest_authenticated_endpoints.py | 11 ++++++++++- bfxapi/rest/types.py | 8 ++++++-- examples/rest/merchant.py | 6 +++++- 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/bfxapi/rest/endpoints/rest_authenticated_endpoints.py b/bfxapi/rest/endpoints/rest_authenticated_endpoints.py index 2dae262..a69ea28 100644 --- a/bfxapi/rest/endpoints/rest_authenticated_endpoints.py +++ b/bfxapi/rest/endpoints/rest_authenticated_endpoints.py @@ -339,4 +339,13 @@ class RestAuthenticatedEndpoints(Middleware): data = to_snake_case_keys(self._POST("auth/w/ext/pay/invoice/create", body=body)) - return InvoiceSubmission.parse(data) \ No newline at end of file + return InvoiceSubmission.parse(data) + + def get_invoices(self, id: Optional[str] = None, start: Optional[str] = None, end: Optional[str] = None, limit: Optional[int] = None) -> List[InvoiceSubmission]: + return [ InvoiceSubmission.parse(sub_data) for sub_data in self._POST("auth/r/ext/pay/invoices", body={ + "id": id, "start": start, "end": end, + "limit": limit + }) ] + + def get_invoice_count_stats(self, status: Literal["CREATED", "PENDING", "COMPLETED", "EXPIRED"], format: str) -> List[InvoiceCountStats]: + return [ InvoiceCountStats(**sub_data) for sub_data in self._POST("auth/r/ext/pay/invoice/stats/count", body={ "status": status, "format": format }) ] \ No newline at end of file diff --git a/bfxapi/rest/types.py b/bfxapi/rest/types.py index 148a60c..5f98ca8 100644 --- a/bfxapi/rest/types.py +++ b/bfxapi/rest/types.py @@ -564,7 +564,6 @@ class DerivativePositionCollateralLimits(_Type): #endregion #region Type hinting for models which are not serializable - @compose(dataclass, partial) class InvoiceSubmission(_Type): id: str @@ -590,7 +589,7 @@ class InvoiceSubmission(_Type): for index, invoice in enumerate(data["invoices"]): data["invoices"][index] = Invoice(**invoice) - return cls(**data) + return InvoiceSubmission(**data) @compose(dataclass, partial) class CustomerInfo(_Type): @@ -614,4 +613,9 @@ class Invoice(_Type): address: str ext: JSON +@dataclass +class InvoiceCountStats(_Type): + time: str + count: float + #endregion \ No newline at end of file diff --git a/examples/rest/merchant.py b/examples/rest/merchant.py index 69a1d8b..a113b3f 100644 --- a/examples/rest/merchant.py +++ b/examples/rest/merchant.py @@ -27,4 +27,8 @@ print(bfx.rest.auth.submit_invoice( order_id="order123", customer_info=customer_info, pay_currencies=["ETH"] -)) \ No newline at end of file +)) + +print(bfx.rest.auth.get_invoices()) + +print(bfx.rest.auth.get_invoice_count_stats(status="CREATED", format="Y")) \ No newline at end of file