From 0300e6261a2ffa97cf994d4c6eccc834ad2a6354 Mon Sep 17 00:00:00 2001 From: Davide Casale Date: Fri, 3 Mar 2023 18:30:25 +0100 Subject: [PATCH] get invoices paginated Co-Authored-By: itsdeka --- .../rest/endpoints/rest_merchant_endpoints.py | 13 +++++++++++++ bfxapi/rest/types.py | 17 +++++++++++++++++ examples/rest/merchant/submit_invoice.py | 4 +++- 3 files changed, 33 insertions(+), 1 deletion(-) diff --git a/bfxapi/rest/endpoints/rest_merchant_endpoints.py b/bfxapi/rest/endpoints/rest_merchant_endpoints.py index 0c80110..d07315a 100644 --- a/bfxapi/rest/endpoints/rest_merchant_endpoints.py +++ b/bfxapi/rest/endpoints/rest_merchant_endpoints.py @@ -31,6 +31,19 @@ class RestMerchantEndpoints(Middleware): "id": id, "start": start, "end": end, "limit": limit })) ] + + def get_invoices_paginated(self, page: int = 1, page_size: int = 10, sort: Literal["asc", "desc"] = "asc", + sort_field: Literal["t", "amount", "status"] = "t", status: Optional[List[Literal["CREATED", "PENDING", "COMPLETED", "EXPIRED"]]] = None, fiat: Optional[List[str]] = None, + crypto: Optional[List[str]] = None, id: Optional[str] = None, order_id: Optional[str] = None) -> InvoicePage: + body = to_camel_case_keys({ + "page": page, "page_size": page_size, "sort": sort, + "sort_field": sort_field, "status": status, "fiat": fiat, + "crypto": crypto, "id": id, "order_id": order_id + }) + + data = to_snake_case_keys(self._POST("auth/r/ext/pay/invoices/paginated", body=body)) + + return InvoicePage.parse(data) def get_invoice_count_stats(self, status: Literal["CREATED", "PENDING", "COMPLETED", "EXPIRED"], format: str) -> List[InvoiceStats]: return [ InvoiceStats(**sub_data) for sub_data in self._POST("auth/r/ext/pay/invoice/stats/count", body={ "status": status, "format": format }) ] diff --git a/bfxapi/rest/types.py b/bfxapi/rest/types.py index 032416d..360e537 100644 --- a/bfxapi/rest/types.py +++ b/bfxapi/rest/types.py @@ -638,6 +638,23 @@ class InvoiceSubmission(_Type): force_completed: bool amount_diff: str +@dataclass +class InvoicePage(_Type): + page: int + page_size: int + sort: Literal["asc", "desc"] + sort_field: Literal["t", "amount", "status"] + total_pages: int + total_items: int + items: List[InvoiceSubmission] + + @classmethod + def parse(cls, data: Dict[str, Any]) -> "InvoicePage": + for index, item in enumerate(data["items"]): + data["items"][index] = InvoiceSubmission.parse(item) + + return InvoicePage(**data) + @dataclass class InvoiceStats(_Type): time: str diff --git a/examples/rest/merchant/submit_invoice.py b/examples/rest/merchant/submit_invoice.py index cb71dce..bec606e 100644 --- a/examples/rest/merchant/submit_invoice.py +++ b/examples/rest/merchant/submit_invoice.py @@ -40,4 +40,6 @@ print(bfx.rest.merchant.complete_invoice( deposit_id=1 )) -print(bfx.rest.merchant.get_invoices(limit=25)) \ No newline at end of file +print(bfx.rest.merchant.get_invoices(limit=25)) + +print(bfx.rest.merchant.get_invoices_paginated(page=1, page_size=60, sort="asc", sort_field="t")) \ No newline at end of file