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,17 +104,26 @@ class Binance(Exchange):
|
|||||||
Assigns property _leverage_brackets to a dictionary of information about the leverage
|
Assigns property _leverage_brackets to a dictionary of information about the leverage
|
||||||
allowed on each pair
|
allowed on each pair
|
||||||
"""
|
"""
|
||||||
leverage_brackets = self._api.load_leverage_brackets()
|
try:
|
||||||
for pair, brackets in leverage_brackets.items:
|
leverage_brackets = self._api.load_leverage_brackets()
|
||||||
self.leverage_brackets[pair] = [
|
for pair, brackets in leverage_brackets.items:
|
||||||
[
|
self.leverage_brackets[pair] = [
|
||||||
min_amount,
|
[
|
||||||
float(margin_req)
|
min_amount,
|
||||||
] for [
|
float(margin_req)
|
||||||
min_amount,
|
] for [
|
||||||
margin_req
|
min_amount,
|
||||||
] in brackets
|
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:
|
def get_max_leverage(self, pair: Optional[str], nominal_value: Optional[float]) -> float:
|
||||||
"""
|
"""
|
||||||
@ -135,4 +144,12 @@ class Binance(Exchange):
|
|||||||
Binance Futures must set the leverage before making a futures trade, in order to not
|
Binance Futures must set the leverage before making a futures trade, in order to not
|
||||||
have the same leverage on every trade
|
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 pair: Here for super method, not used on FTX
|
||||||
:param leverage:
|
: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
|
# TODO-lev: Not sure if this works correctly for futures
|
||||||
leverages = {}
|
leverages = {}
|
||||||
for pair, market in self._api.load_markets().items():
|
try:
|
||||||
info = market['info']
|
for pair, market in self._api.load_markets().items():
|
||||||
leverage_buy = info['leverage_buy']
|
info = market['info']
|
||||||
leverage_sell = info['leverage_sell']
|
leverage_buy = info['leverage_buy']
|
||||||
if len(info['leverage_buy']) > 0 or len(info['leverage_sell']) > 0:
|
leverage_sell = info['leverage_sell']
|
||||||
if leverage_buy != leverage_sell:
|
if len(info['leverage_buy']) > 0 or len(info['leverage_sell']) > 0:
|
||||||
print(f"\033[91m The buy leverage != the sell leverage for {pair}."
|
if leverage_buy != leverage_sell:
|
||||||
"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
|
if max(leverage_buy) < max(leverage_sell):
|
||||||
|
leverages[pair] = leverage_buy
|
||||||
|
else:
|
||||||
|
leverages[pair] = leverage_sell
|
||||||
else:
|
else:
|
||||||
leverages[pair] = leverage_sell
|
leverages[pair] = leverage_buy
|
||||||
else:
|
self._leverage_brackets = leverages
|
||||||
leverages[pair] = leverage_buy
|
except ccxt.DDoSProtection as e:
|
||||||
self._leverage_brackets = leverages
|
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:
|
def get_max_leverage(self, pair: Optional[str], nominal_value: Optional[float]) -> float:
|
||||||
"""
|
"""
|
||||||
|
Loading…
Reference in New Issue
Block a user