From 7562b21ada5bd3c00502f61d31c142de93b471fe Mon Sep 17 00:00:00 2001 From: Davide Casale Date: Fri, 3 Mar 2023 20:03:23 +0100 Subject: [PATCH] settings Co-Authored-By: itsdeka --- .../rest/endpoints/rest_merchant_endpoints.py | 25 +++++++++++++++-- bfxapi/rest/enums.py | 14 ++++++++-- bfxapi/rest/types.py | 28 +++++++++++++++++++ examples/rest/merchant/settings.py | 28 +++++++++++++++++++ 4 files changed, 91 insertions(+), 4 deletions(-) create mode 100644 examples/rest/merchant/settings.py diff --git a/bfxapi/rest/endpoints/rest_merchant_endpoints.py b/bfxapi/rest/endpoints/rest_merchant_endpoints.py index d07315a..2e445ce 100644 --- a/bfxapi/rest/endpoints/rest_merchant_endpoints.py +++ b/bfxapi/rest/endpoints/rest_merchant_endpoints.py @@ -1,9 +1,11 @@ -from typing import TypedDict, List, Union, Literal, Optional +from typing import TypedDict, List, Union, Literal, Optional, Any from decimal import Decimal from .. types import * +from .. enums import MerchantSettingsKey from .. middleware import Middleware + from ...utils.camel_and_snake_case_helpers import to_snake_case_keys, to_camel_case_keys _CustomerInfo = TypedDict("_CustomerInfo", { @@ -79,4 +81,23 @@ class RestMerchantEndpoints(Middleware): return bool(self._POST("auth/w/ext/pay/settings/convert/remove", body={ "baseCcy": base_currency, "convertCcy": convert_currency - })) \ No newline at end of file + })) + + def set_merchant_settings(self, key: MerchantSettingsKey, val: Any) -> bool: + return bool(self._POST("auth/w/ext/pay/settings/set", body={ "key": key, "val": val })) + + def get_merchant_settings(self, key: MerchantSettingsKey) -> Any: + return self._POST("auth/r/ext/pay/settings/get", body={ "key": key }) + + def list_merchant_settings(self, keys: List[MerchantSettingsKey] = list()) -> Dict[MerchantSettingsKey, Any]: + return self._POST("auth/r/ext/pay/settings/list", body={ "keys": keys }) + + def get_deposits(self, start: int, end: int, ccy: Optional[str] = None, unlinked: Optional[bool] = None) -> List[MerchantDeposit]: + return [ MerchantDeposit(**sub_data) for sub_data in to_snake_case_keys(self._POST("auth/r/ext/pay/deposits", body={ + "from": start, "to": end, "ccy": ccy, "unlinked": unlinked + })) ] + + def get_unlinked_deposits(self, ccy: str, start: Optional[int] = None, end: Optional[int] = None) -> List[MerchantUnlinkedDeposit]: + return [ MerchantUnlinkedDeposit(**sub_data) for sub_data in to_snake_case_keys(self._POST("/auth/r/ext/pay/deposits/unlinked", body={ + "ccy": ccy, "start": start, "end": end + })) ] \ No newline at end of file diff --git a/bfxapi/rest/enums.py b/bfxapi/rest/enums.py index 65c1e1a..c256a34 100644 --- a/bfxapi/rest/enums.py +++ b/bfxapi/rest/enums.py @@ -21,7 +21,7 @@ class Config(str, Enum): INFO_PAIR_FUTURES = "pub:info:pair:futures" INFO_TX_STATUS = "pub:info:tx:status" - SPEC_MARGIN = "pub:spec:margin", + SPEC_MARGIN = "pub:spec:margin" FEES = "pub:fees" class Precision(str, Enum): @@ -33,4 +33,14 @@ class Precision(str, Enum): class Sort(int, Enum): ASCENDING = +1 - DESCENDING = -1 \ No newline at end of file + DESCENDING = -1 + +class MerchantSettingsKey(str, Enum): + PREFERRED_FIAT = "bfx_pay_preferred_fiat" + RECOMMEND_STORE = "bfx_pay_recommend_store" + NOTIFY_PAYMENT_COMPLETED = "bfx_pay_notify_payment_completed" + NOTIFY_PAYMENT_COMPLETED_EMAIL = "bfx_pay_notify_payment_completed_email" + NOTIFY_AUTOCONVERT_EXECUTED = "bfx_pay_notify_autoconvert_executed" + DUST_BALANCE_UI = "bfx_pay_dust_balance_ui" + MERCHANT_CUSTOMER_SUPPORT_URL = "bfx_pay_merchant_customer_support_url" + MERCHANT_UNDERPAID_THRESHOLD = "bfx_pay_merchant_underpaid_threshold" \ No newline at end of file diff --git a/bfxapi/rest/types.py b/bfxapi/rest/types.py index 360e537..9e3e752 100644 --- a/bfxapi/rest/types.py +++ b/bfxapi/rest/types.py @@ -666,4 +666,32 @@ class CurrencyConversion(_Type): convert_currency: str created: int +@dataclass +class MerchantDeposit(_Type): + id: int + invoice_id: Optional[str] + order_id: Optional[str] + type: Literal["ledger", "deposit"] + amount: float + t: int + txid: str + currency: str + method: str + pay_method: str + +@dataclass +class MerchantUnlinkedDeposit(_Type): + id: int + method: str + currency: str + created_at: int + updated_at: int + amount: float + fee: float + txid: str + address: str + payment_id: Optional[int] + status: str + note: Optional[str] + #endregion \ No newline at end of file diff --git a/examples/rest/merchant/settings.py b/examples/rest/merchant/settings.py new file mode 100644 index 0000000..4afe06b --- /dev/null +++ b/examples/rest/merchant/settings.py @@ -0,0 +1,28 @@ +# python -c "import examples.rest.merchant.settings" + +import os + +from bfxapi import Client, REST_HOST + +from bfxapi.rest.enums import MerchantSettingsKey + +bfx = Client( + REST_HOST=REST_HOST, + API_KEY=os.getenv("BFX_API_KEY"), + API_SECRET=os.getenv("BFX_API_SECRET") +) + +if not bfx.rest.merchant.set_merchant_settings(MerchantSettingsKey.RECOMMEND_STORE, 1): + print(f"Cannot set <{MerchantSettingsKey.RECOMMEND_STORE}> to <1>.") + +print(f"The current <{MerchantSettingsKey.PREFERRED_FIAT}> value is:", + bfx.rest.merchant.get_merchant_settings(MerchantSettingsKey.PREFERRED_FIAT)) + +settings = bfx.rest.merchant.list_merchant_settings([ + MerchantSettingsKey.DUST_BALANCE_UI, + MerchantSettingsKey.MERCHANT_CUSTOMER_SUPPORT_URL, + MerchantSettingsKey.MERCHANT_UNDERPAID_THRESHOLD +]) + +for key, value in settings.items(): + print(f"<{key}>:", value) \ No newline at end of file