Added error handlers to api functions and made a logger warning in fill_leverage_brackets
This commit is contained in:
parent
84bc4dd740
commit
f5fd8dcc05
@ -103,17 +103,26 @@ class Binance(Exchange):
|
||||
Assigns property _leverage_brackets to a dictionary of information about the leverage
|
||||
allowed on each pair
|
||||
"""
|
||||
leverage_brackets = self._api.load_leverage_brackets()
|
||||
for pair, brackets in leverage_brackets.items:
|
||||
self.leverage_brackets[pair] = [
|
||||
[
|
||||
min_amount,
|
||||
float(margin_req)
|
||||
] for [
|
||||
min_amount,
|
||||
margin_req
|
||||
] in brackets
|
||||
]
|
||||
try:
|
||||
leverage_brackets = self._api.load_leverage_brackets()
|
||||
for pair, brackets in leverage_brackets.items:
|
||||
self.leverage_brackets[pair] = [
|
||||
[
|
||||
min_amount,
|
||||
float(margin_req)
|
||||
] for [
|
||||
min_amount,
|
||||
margin_req
|
||||
] 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:
|
||||
"""
|
||||
@ -134,4 +143,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
|
||||
"""
|
||||
self._api.set_leverage(symbol=pair, leverage=leverage)
|
||||
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:
|
||||
"""
|
||||
self._api.private_post_account_leverage({'leverage': 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,22 +135,30 @@ class Kraken(Exchange):
|
||||
"""
|
||||
# TODO-lev: Not sure if this works correctly for futures
|
||||
leverages = {}
|
||||
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"
|
||||
)
|
||||
if max(leverage_buy) < max(leverage_sell):
|
||||
leverages[pair] = leverage_buy
|
||||
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:
|
||||
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
|
||||
else:
|
||||
leverages[pair] = leverage_sell
|
||||
else:
|
||||
leverages[pair] = leverage_sell
|
||||
else:
|
||||
leverages[pair] = leverage_buy
|
||||
self._leverage_brackets = leverages
|
||||
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