mirror of
https://github.com/freqtrade/freqtrade.git
synced 2025-12-01 01:23:04 +00:00
Extract funding fee calculation to separate method
This commit is contained in:
@@ -725,16 +725,7 @@ class Backtesting:
|
||||
self, trade: LocalTrade, row: Tuple, current_time: datetime
|
||||
) -> Optional[LocalTrade]:
|
||||
|
||||
if self.trading_mode == TradingMode.FUTURES:
|
||||
trade.set_funding_fees(
|
||||
self.exchange.calculate_funding_fees(
|
||||
self.futures_data[trade.pair],
|
||||
amount=trade.amount,
|
||||
is_short=trade.is_short,
|
||||
open_date=trade.date_last_filled_utc,
|
||||
close_date=current_time
|
||||
)
|
||||
)
|
||||
self._run_funding_fees(trade, current_time)
|
||||
|
||||
# Check if we need to adjust our current positions
|
||||
if self.strategy.position_adjustment_enable:
|
||||
@@ -753,6 +744,21 @@ class Backtesting:
|
||||
return t
|
||||
return None
|
||||
|
||||
def _run_funding_fees(self, trade: Trade, current_time: datetime):
|
||||
"""
|
||||
Calculate funding fees if necessary and add them to the trade.
|
||||
"""
|
||||
if self.trading_mode == TradingMode.FUTURES:
|
||||
trade.set_funding_fees(
|
||||
self.exchange.calculate_funding_fees(
|
||||
self.futures_data[trade.pair],
|
||||
amount=trade.amount,
|
||||
is_short=trade.is_short,
|
||||
open_date=trade.date_last_filled_utc,
|
||||
close_date=current_time
|
||||
)
|
||||
)
|
||||
|
||||
def get_valid_price_and_stake(
|
||||
self, pair: str, row: Tuple, propose_rate: float, stake_amount: float,
|
||||
direction: LongShort, current_time: datetime, entry_tag: Optional[str],
|
||||
|
||||
Reference in New Issue
Block a user