Added exceptions to exchange.interest_rate

This commit is contained in:
Sam Germain 2021-09-04 19:47:04 -06:00
parent 97d1306e34
commit 619ecc9728
2 changed files with 35 additions and 2 deletions

View File

@ -1562,13 +1562,22 @@ class Exchange:
is_short: bool is_short: bool
) -> Tuple[float, float]: ) -> Tuple[float, float]:
""" """
Gets the rate of interest for borrowed currency when margin trading
:param pair: base/quote currency pair :param pair: base/quote currency pair
:param maker_or_taker: "maker" if limit order, "taker" if market order :param maker_or_taker: "maker" if limit order, "taker" if market order
:param is_short: True if requesting base interest, False if requesting quote interest :param is_short: True if requesting base interest, False if requesting quote interest
:return: (open_interest, rollover_interest) :return: (open_interest, rollover_interest)
""" """
# TODO-lev: implement try:
return (0.0005, 0.0005) # TODO-lev: implement, currently there is no ccxt method for this
return (0.0005, 0.0005)
except ccxt.DDoSProtection as e:
raise DDosProtection(e) from e
except (ccxt.NetworkError, ccxt.ExchangeError) as e:
raise TemporaryError(
f'Could not set leverage due to {e.__class__.__name__}. Message: {e}') from e
except ccxt.BaseError as e:
raise OperationalException(e) from e
@retrier @retrier
def fill_leverage_brackets(self): def fill_leverage_brackets(self):

View File

@ -3031,6 +3031,30 @@ def test_get_interest_rate(
pair, maker_or_taker, is_short) == (borrow_rate, interest_rate) pair, maker_or_taker, is_short) == (borrow_rate, interest_rate)
@pytest.mark.parametrize("exchange_name", [("binance"), ("ftx"), ("kraken")])
@pytest.mark.parametrize("maker_or_taker", [("maker"), ("taker")])
@pytest.mark.parametrize("is_short", [(True), (False)])
def test_get_interest_rate_exceptions(mocker, default_conf, exchange_name, maker_or_taker, is_short):
# api_mock = MagicMock()
# # TODO-lev: get_interest_rate currently not implemented on CCXT, so this may need to be renamed
# api_mock.get_interest_rate = MagicMock()
# type(api_mock).has = PropertyMock(return_value={'getInterestRate': True})
# ccxt_exceptionhandlers(
# mocker,
# default_conf,
# api_mock,
# exchange_name,
# "get_interest_rate",
# "get_interest_rate",
# pair="XRP/USDT",
# is_short=is_short,
# maker_or_taker="maker_or_taker"
# )
return
@pytest.mark.parametrize("collateral", [ @pytest.mark.parametrize("collateral", [
(Collateral.CROSS), (Collateral.CROSS),
(Collateral.ISOLATED) (Collateral.ISOLATED)