Added error handlers to api functions and made a logger warning in fill_leverage_brackets
This commit is contained in:
parent
c256dc3745
commit
16db8d70a5
@ -104,6 +104,7 @@ class Binance(Exchange):
|
||||
Assigns property _leverage_brackets to a dictionary of information about the leverage
|
||||
allowed on each pair
|
||||
"""
|
||||
try:
|
||||
leverage_brackets = self._api.load_leverage_brackets()
|
||||
for pair, brackets in leverage_brackets.items:
|
||||
self.leverage_brackets[pair] = [
|
||||
@ -116,6 +117,14 @@ class Binance(Exchange):
|
||||
] in brackets
|
||||
]
|
||||
|
||||
except ccxt.DDoSProtection as e:
|
||||
raise DDosProtection(e) from e
|
||||
except (ccxt.NetworkError, ccxt.ExchangeError) as e:
|
||||
raise TemporaryError(f'Could not fetch leverage amounts due to'
|
||||
f'{e.__class__.__name__}. Message: {e}') from e
|
||||
except ccxt.BaseError as e:
|
||||
raise OperationalException(e) from e
|
||||
|
||||
def get_max_leverage(self, pair: Optional[str], nominal_value: Optional[float]) -> float:
|
||||
"""
|
||||
Returns the maximum leverage that a pair can be traded at
|
||||
@ -135,4 +144,12 @@ class Binance(Exchange):
|
||||
Binance Futures must set the leverage before making a futures trade, in order to not
|
||||
have the same leverage on every trade
|
||||
"""
|
||||
try:
|
||||
self._api.set_leverage(symbol=pair, leverage=leverage)
|
||||
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
|
||||
|
@ -182,4 +182,12 @@ class Ftx(Exchange):
|
||||
:param pair: Here for super method, not used on FTX
|
||||
:param leverage:
|
||||
"""
|
||||
try:
|
||||
self._api.private_post_account_leverage({'leverage': leverage})
|
||||
except ccxt.DDoSProtection as e:
|
||||
raise DDosProtection(e) from e
|
||||
except (ccxt.NetworkError, ccxt.ExchangeError) as e:
|
||||
raise TemporaryError(f'Could not fetch leverage amounts due to'
|
||||
f'{e.__class__.__name__}. Message: {e}') from e
|
||||
except ccxt.BaseError as e:
|
||||
raise OperationalException(e) from e
|
||||
|
@ -135,14 +135,15 @@ class Kraken(Exchange):
|
||||
"""
|
||||
# TODO-lev: Not sure if this works correctly for futures
|
||||
leverages = {}
|
||||
try:
|
||||
for pair, market in self._api.load_markets().items():
|
||||
info = market['info']
|
||||
leverage_buy = info['leverage_buy']
|
||||
leverage_sell = info['leverage_sell']
|
||||
if len(info['leverage_buy']) > 0 or len(info['leverage_sell']) > 0:
|
||||
if leverage_buy != leverage_sell:
|
||||
print(f"\033[91m The buy leverage != the sell leverage for {pair}."
|
||||
"please let freqtrade know because this has never happened before"
|
||||
logger.warning(f"The buy leverage != the sell leverage for {pair}. Please"
|
||||
"let freqtrade know because this has never happened before"
|
||||
)
|
||||
if max(leverage_buy) < max(leverage_sell):
|
||||
leverages[pair] = leverage_buy
|
||||
@ -151,6 +152,13 @@ class Kraken(Exchange):
|
||||
else:
|
||||
leverages[pair] = leverage_buy
|
||||
self._leverage_brackets = leverages
|
||||
except ccxt.DDoSProtection as e:
|
||||
raise DDosProtection(e) from e
|
||||
except (ccxt.NetworkError, ccxt.ExchangeError) as e:
|
||||
raise TemporaryError(f'Could not fetch leverage amounts due to'
|
||||
f'{e.__class__.__name__}. Message: {e}') from e
|
||||
except ccxt.BaseError as e:
|
||||
raise OperationalException(e) from e
|
||||
|
||||
def get_max_leverage(self, pair: Optional[str], nominal_value: Optional[float]) -> float:
|
||||
"""
|
||||
|
Loading…
Reference in New Issue
Block a user