diff --git a/bfxapi/rest/endpoints/rest_authenticated_endpoints.py b/bfxapi/rest/endpoints/rest_authenticated_endpoints.py index 1493489..9ec3ca0 100644 --- a/bfxapi/rest/endpoints/rest_authenticated_endpoints.py +++ b/bfxapi/rest/endpoints/rest_authenticated_endpoints.py @@ -347,8 +347,26 @@ class RestAuthenticatedEndpoints(Middleware): "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 }) ] + 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 }) ] - def get_invoice_earning_stats(self, currency: str, format: str) -> List[InvoiceEarningStats]: - return [ InvoiceEarningStats(**sub_data) for sub_data in self._POST("auth/r/ext/pay/invoice/stats/earning", body={ "currency": currency, "format": format }) ] \ No newline at end of file + def get_invoice_earning_stats(self, currency: str, format: str) -> List[InvoiceStats]: + return [ InvoiceStats(**sub_data) for sub_data in self._POST("auth/r/ext/pay/invoice/stats/earning", body={ "currency": currency, "format": format }) ] + + def complete_invoice(self, id: str, pay_currency: str, deposit_id: Optional[int] = None, ledger_id: Optional[int] = None) -> InvoiceSubmission: + return InvoiceSubmission.parse(self._POST("auth/w/ext/pay/invoice/complete", body={ + "id": id, "payCcy": pay_currency, "depositId": deposit_id, + "ledgerId": ledger_id + })) + + def expire_invoice(self, id: str) -> InvoiceSubmission: + return InvoiceSubmission.parse(self._POST("auth/w/ext/pay/invoice/expire", body={ "id": id })) + + def get_currency_conversion_list(self) -> List[CurrencyConversion]: + return [ + CurrencyConversion( + base_currency=sub_data["baseCcy"], + convert_currency=sub_data["convertCcy"], + created=sub_data["created"] + ) for sub_data in self._POST("auth/r/ext/pay/settings/convert/list") + ] \ No newline at end of file diff --git a/bfxapi/rest/types.py b/bfxapi/rest/types.py index 3d659b4..a2dd647 100644 --- a/bfxapi/rest/types.py +++ b/bfxapi/rest/types.py @@ -564,20 +564,21 @@ class DerivativePositionCollateralLimits(_Type): #endregion #region Type hinting for models which are not serializable + @compose(dataclass, partial) class InvoiceSubmission(_Type): id: str t: int + merchant_name: str type: Literal["ECOMMERCE", "POS"] duration: int amount: float currency: str order_id: str pay_currencies: List[str] - webhook: str - redirect_url: str status: Literal["CREATED", "PENDING", "COMPLETED", "EXPIRED"] customer_info: Optional["CustomerInfo"] + payment: Optional["Payment"] invoices: List["Invoice"] @classmethod @@ -585,6 +586,9 @@ class InvoiceSubmission(_Type): if "customer_info" in data and data["customer_info"] != None: data["customer_info"] = CustomerInfo(**data["customer_info"]) + if "payment" in data and data["payment"] != None: + data["payment"] = Payment(**data["payment"]) + if "invoices" in data and data["invoices"] != None: for index, invoice in enumerate(data["invoices"]): data["invoices"][index] = Invoice(**invoice) @@ -595,7 +599,6 @@ class InvoiceSubmission(_Type): class CustomerInfo(_Type): nationality: str resid_country: str - resid_state: str resid_city: str resid_zip_code: str resid_street: str @@ -604,6 +607,23 @@ class CustomerInfo(_Type): email: str tos_accepted: bool +@compose(dataclass, partial) +class Payment(_Type): + transaction_id: str + amount: str + currency: str + method: str + status: str + confirmations: int + created: str + updated: str + deposit_id: int + ledger_id: int + force_completed: bool + amount_diff: str + additional_payments: JSON + additional_payment: JSON + @compose(dataclass, partial) class Invoice(_Type): amount: float @@ -614,13 +634,14 @@ class Invoice(_Type): ext: JSON @dataclass -class InvoiceCountStats(_Type): +class InvoiceStats(_Type): time: str count: float @dataclass -class InvoiceEarningStats(_Type): - time: str - count: float +class CurrencyConversion(_Type): + base_currency: str + convert_currency: str + created: int #endregion \ No newline at end of file diff --git a/examples/rest/merchant.py b/examples/rest/merchant.py index 9e85d88..7a4c835 100644 --- a/examples/rest/merchant.py +++ b/examples/rest/merchant.py @@ -20,17 +20,25 @@ customer_info = { "email": "satoshi3@bitfinex.com" } -print(bfx.rest.auth.submit_invoice( +invoice = bfx.rest.auth.submit_invoice( amount=1, currency="USD", duration=864000, order_id="order123", customer_info=customer_info, pay_currencies=["ETH"] -)) +) print(bfx.rest.auth.get_invoices()) print(bfx.rest.auth.get_invoice_count_stats(status="CREATED", format="Y")) -print(bfx.rest.auth.get_invoice_earning_stats(currency="USD", format="Y")) \ No newline at end of file +print(bfx.rest.auth.get_invoice_earning_stats(currency="USD", format="Y")) + +print(bfx.rest.auth.get_currency_conversion_list()) + +print(bfx.rest.auth.complete_invoice( + id=invoice.id, + pay_currency="ETH", + deposit_id=1 +)) \ No newline at end of file