From e198bbf1b882650f7aef256721064bbae27f2651 Mon Sep 17 00:00:00 2001 From: "Benjamin T. Schwertfeger" Date: Sat, 21 Oct 2023 17:52:39 +0200 Subject: [PATCH] Add `max_fee` parameter to `kraken.spot.Funding.withdraw_funds` (#171) --- kraken/exceptions/__init__.py | 7 +++++++ kraken/spot/funding.py | 10 +++++++++- tests/spot/test_spot_funding.py | 1 + 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/kraken/exceptions/__init__.py b/kraken/exceptions/__init__.py index fcaaf15a..a3d782f8 100644 --- a/kraken/exceptions/__init__.py +++ b/kraken/exceptions/__init__.py @@ -272,6 +272,11 @@ class KrakenTemporaryLockoutError(Exception): """The account was temporary locked out.""" +@docstring_message +class KrakenMaxFeeExceededError(Exception): + """The fee was higher than the defined maximum.""" + + @docstring_message class MaxReconnectError(Exception): """To many reconnect tries.""" @@ -286,6 +291,7 @@ class MaxReconnectError(Exception): "EGeneral:Permission denied": KrakenPermissionDeniedError, "EGeneral:Unknown method": KrakenUnknownMethodError, "EGeneral:Temporary lockout": KrakenTemporaryLockoutError, + "EFunding:Max fee exceeded": KrakenMaxFeeExceededError, "EService:Unavailable": KrakenServiceUnavailableError, "EService:Market in cancel_only mode": KrakenMarketInOnlyCancelModeError, "EService:Market in post_only mode": KrakenMarketInOnlyPostModeError, @@ -379,6 +385,7 @@ def _get_exception(data: str | list[str]) -> Optional[Any]: "KrakenMarginPositionSizeExceededError", "KrakenMarketInOnlyCancelModeError", "KrakenMarketInOnlyPostModeError", + "KrakenMaxFeeExceededError", "KrakenNotFoundError", "KrakenOrderForEditNotFoundError", "KrakenOrderLimitsExceededError", diff --git a/kraken/spot/funding.py b/kraken/spot/funding.py index 4572c971..01dc7782 100644 --- a/kraken/spot/funding.py +++ b/kraken/spot/funding.py @@ -301,6 +301,7 @@ def withdraw_funds( asset: str, key: str, amount: str | float, + max_fee: Optional[str] = None, *, extra_params: Optional[dict] = None, ) -> dict: @@ -318,6 +319,9 @@ def withdraw_funds( :type key: str :param amount: The amount to withdraw :type amount: str | float + :param max_fee: Fail withdraw if the fee will be higher than the + specified max_fee. + :type max_fee: str :return: The reference id of the withdraw :rtype: dict @@ -334,10 +338,14 @@ def withdraw_funds( ... ) { 'refid': 'I7KGS6-UFMTTQ-AGBSO6T'} """ + params: dict = {"asset": asset, "key": str(key), "amount": str(amount)} + if defined(max_fee): + params["max_fee"] = max_fee + return self._request( # type: ignore[return-value] method="POST", uri="/private/Withdraw", - params={"asset": asset, "key": str(key), "amount": str(amount)}, + params=params, extra_params=extra_params, ) diff --git a/tests/spot/test_spot_funding.py b/tests/spot/test_spot_funding.py index 4ed1bbfb..8518ebaf 100644 --- a/tests/spot/test_spot_funding.py +++ b/tests/spot/test_spot_funding.py @@ -89,6 +89,7 @@ def test_withdraw_funds(spot_auth_funding: Funding) -> None: asset="XLM", key="enter-withdraw-key", amount=10000000, + max_fee=20, ), )