Don't crash in case of funding fee fetch error
This commit is contained in:
parent
20bf44a856
commit
4e15611b05
@ -2509,8 +2509,13 @@ class Exchange:
|
|||||||
cache=False,
|
cache=False,
|
||||||
drop_incomplete=False,
|
drop_incomplete=False,
|
||||||
)
|
)
|
||||||
|
try:
|
||||||
|
# we can't assume we always get histories - for example during exchange downtimes
|
||||||
funding_rates = candle_histories[funding_comb]
|
funding_rates = candle_histories[funding_comb]
|
||||||
mark_rates = candle_histories[mark_comb]
|
mark_rates = candle_histories[mark_comb]
|
||||||
|
except KeyError:
|
||||||
|
raise ExchangeError("Could not find funding rates") from None
|
||||||
|
|
||||||
funding_mark_rates = self.combine_funding_and_mark(
|
funding_mark_rates = self.combine_funding_and_mark(
|
||||||
funding_rates=funding_rates, mark_rates=mark_rates)
|
funding_rates=funding_rates, mark_rates=mark_rates)
|
||||||
|
|
||||||
@ -2590,6 +2595,8 @@ class Exchange:
|
|||||||
:param is_short: trade direction
|
:param is_short: trade direction
|
||||||
:param amount: Trade amount
|
:param amount: Trade amount
|
||||||
:param open_date: Open date of the trade
|
:param open_date: Open date of the trade
|
||||||
|
:return: funding fee since open_date
|
||||||
|
:raies: ExchangeError if something goes wrong.
|
||||||
"""
|
"""
|
||||||
if self.trading_mode == TradingMode.FUTURES:
|
if self.trading_mode == TradingMode.FUTURES:
|
||||||
if self._config['dry_run']:
|
if self._config['dry_run']:
|
||||||
|
@ -281,6 +281,7 @@ class FreqtradeBot(LoggingMixin):
|
|||||||
def update_funding_fees(self):
|
def update_funding_fees(self):
|
||||||
if self.trading_mode == TradingMode.FUTURES:
|
if self.trading_mode == TradingMode.FUTURES:
|
||||||
trades = Trade.get_open_trades()
|
trades = Trade.get_open_trades()
|
||||||
|
try:
|
||||||
for trade in trades:
|
for trade in trades:
|
||||||
funding_fees = self.exchange.get_funding_fees(
|
funding_fees = self.exchange.get_funding_fees(
|
||||||
pair=trade.pair,
|
pair=trade.pair,
|
||||||
@ -289,6 +290,8 @@ class FreqtradeBot(LoggingMixin):
|
|||||||
open_date=trade.date_last_filled_utc
|
open_date=trade.date_last_filled_utc
|
||||||
)
|
)
|
||||||
trade.funding_fees = funding_fees
|
trade.funding_fees = funding_fees
|
||||||
|
except ExchangeError:
|
||||||
|
logger.warning("Could not update funding fees for open trades.")
|
||||||
else:
|
else:
|
||||||
return 0.0
|
return 0.0
|
||||||
|
|
||||||
@ -671,14 +674,12 @@ class FreqtradeBot(LoggingMixin):
|
|||||||
if not stake_amount:
|
if not stake_amount:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
if pos_adjust:
|
msg = (f"Position adjust: about to create a new order for {pair} with stake: "
|
||||||
logger.info(f"Position adjust: about to create a new order for {pair} with stake: "
|
f"{stake_amount} for {trade}" if pos_adjust
|
||||||
f"{stake_amount} for {trade}")
|
else
|
||||||
else:
|
|
||||||
logger.info(
|
|
||||||
f"{name} signal found: about create a new trade for {pair} with stake_amount: "
|
f"{name} signal found: about create a new trade for {pair} with stake_amount: "
|
||||||
f"{stake_amount} ...")
|
f"{stake_amount} ...")
|
||||||
|
logger.info(msg)
|
||||||
amount = (stake_amount / enter_limit_requested) * leverage
|
amount = (stake_amount / enter_limit_requested) * leverage
|
||||||
order_type = ordertype or self.strategy.order_types['entry']
|
order_type = ordertype or self.strategy.order_types['entry']
|
||||||
|
|
||||||
@ -741,8 +742,12 @@ class FreqtradeBot(LoggingMixin):
|
|||||||
|
|
||||||
# This is a new trade
|
# This is a new trade
|
||||||
if trade is None:
|
if trade is None:
|
||||||
|
try:
|
||||||
funding_fees = self.exchange.get_funding_fees(
|
funding_fees = self.exchange.get_funding_fees(
|
||||||
pair=pair, amount=amount, is_short=is_short, open_date=open_date)
|
pair=pair, amount=amount, is_short=is_short, open_date=open_date)
|
||||||
|
except ExchangeError:
|
||||||
|
logger.warning("Could not update funding fee.")
|
||||||
|
|
||||||
trade = Trade(
|
trade = Trade(
|
||||||
pair=pair,
|
pair=pair,
|
||||||
base_currency=base_currency,
|
base_currency=base_currency,
|
||||||
@ -1493,12 +1498,16 @@ class FreqtradeBot(LoggingMixin):
|
|||||||
:param exit_check: CheckTuple with signal and reason
|
:param exit_check: CheckTuple with signal and reason
|
||||||
:return: True if it succeeds False
|
:return: True if it succeeds False
|
||||||
"""
|
"""
|
||||||
|
try:
|
||||||
trade.funding_fees = self.exchange.get_funding_fees(
|
trade.funding_fees = self.exchange.get_funding_fees(
|
||||||
pair=trade.pair,
|
pair=trade.pair,
|
||||||
amount=trade.amount,
|
amount=trade.amount,
|
||||||
is_short=trade.is_short,
|
is_short=trade.is_short,
|
||||||
open_date=trade.date_last_filled_utc,
|
open_date=trade.date_last_filled_utc,
|
||||||
)
|
)
|
||||||
|
except ExchangeError:
|
||||||
|
logger.warning("Could not update funding fee.")
|
||||||
|
|
||||||
exit_type = 'exit'
|
exit_type = 'exit'
|
||||||
exit_reason = exit_tag or exit_check.exit_reason
|
exit_reason = exit_tag or exit_check.exit_reason
|
||||||
if exit_check.exit_type in (
|
if exit_check.exit_type in (
|
||||||
|
Loading…
Reference in New Issue
Block a user