mirror of
https://github.com/freqtrade/freqtrade.git
synced 2024-11-10 10:21:59 +00:00
Add "migrate funding fee timeframe" logic
This commit is contained in:
parent
a12f368796
commit
983764ad0a
|
@ -531,7 +531,7 @@ def download_data_main(config: Config) -> None:
|
|||
"Please use `--dl-trades` instead for this exchange "
|
||||
"(will unfortunately take a long time)."
|
||||
)
|
||||
migrate_data(config)
|
||||
migrate_data(config, exchange)
|
||||
pairs_not_available = refresh_backtest_ohlcv_data(
|
||||
exchange, pairs=expanded_pairs, timeframes=config['timeframes'],
|
||||
datadir=config['datadir'], timerange=timerange,
|
||||
|
|
|
@ -403,6 +403,30 @@ class IDataHandler(ABC):
|
|||
return
|
||||
file_old.rename(file_new)
|
||||
|
||||
def fix_funding_fee_timeframe(self, ff_timeframe: str):
|
||||
"""
|
||||
Temporary method to migrate data from old funding fee timeframe to the correct timeframe
|
||||
Applies to bybit and okx, where funding-fee and mark candles have different timeframes.
|
||||
"""
|
||||
paircombs = self.ohlcv_get_available_data(self._datadir, TradingMode.FUTURES)
|
||||
funding_rate_combs = [
|
||||
f for f in paircombs if f[2] == CandleType.FUNDING_RATE and f[1] != ff_timeframe
|
||||
]
|
||||
|
||||
for pair, timeframe, candletype in funding_rate_combs:
|
||||
old_name = self._pair_data_filename(self._datadir, pair, timeframe, candletype)
|
||||
new_name = self._pair_data_filename(self._datadir, pair, ff_timeframe, candletype)
|
||||
|
||||
if not Path(old_name).exists():
|
||||
logger.warning(f'{old_name} does not exist, skipping.')
|
||||
continue
|
||||
|
||||
if Path(new_name).exists():
|
||||
logger.warning(f'{new_name} already exists, skipping.')
|
||||
continue
|
||||
|
||||
Path(old_name).rename(new_name)
|
||||
|
||||
|
||||
def get_datahandlerclass(datatype: str) -> Type[IDataHandler]:
|
||||
"""
|
||||
|
|
|
@ -158,7 +158,7 @@ class Backtesting:
|
|||
self._can_short = self.trading_mode != TradingMode.SPOT
|
||||
self._position_stacking: bool = self.config.get('position_stacking', False)
|
||||
self.enable_protections: bool = self.config.get('enable_protections', False)
|
||||
migrate_data(config)
|
||||
migrate_data(config, self.exchange)
|
||||
|
||||
self.init_backtest()
|
||||
|
||||
|
|
|
@ -1,6 +1,12 @@
|
|||
from typing import Optional
|
||||
|
||||
from freqtrade.exchange import Exchange
|
||||
from freqtrade.util.migrations.binance_mig import migrate_binance_futures_names # noqa F401
|
||||
from freqtrade.util.migrations.binance_mig import migrate_binance_futures_data
|
||||
from freqtrade.util.migrations.funding_fee_mig import migrate_funding_fee_timeframe
|
||||
|
||||
|
||||
def migrate_data(config):
|
||||
def migrate_data(config, exchange: Optional[Exchange] = None):
|
||||
migrate_binance_futures_data(config)
|
||||
|
||||
migrate_funding_fee_timeframe(config, exchange)
|
||||
|
|
29
freqtrade/util/migrations/funding_fee_mig.py
Normal file
29
freqtrade/util/migrations/funding_fee_mig.py
Normal file
|
@ -0,0 +1,29 @@
|
|||
import logging
|
||||
from typing import Optional
|
||||
|
||||
from freqtrade.constants import Config
|
||||
from freqtrade.data.history.idatahandler import get_datahandler
|
||||
from freqtrade.enums import TradingMode
|
||||
from freqtrade.exchange import Exchange
|
||||
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def migrate_funding_fee_timeframe(config: Config, exchange: Optional[Exchange]):
|
||||
if (
|
||||
config.get('trading_mode', TradingMode.SPOT) != TradingMode.FUTURES
|
||||
):
|
||||
# only act on futures
|
||||
return
|
||||
|
||||
if not exchange:
|
||||
from freqtrade.resolvers import ExchangeResolver
|
||||
exchange = ExchangeResolver.load_exchange(config, validate=False)
|
||||
|
||||
ff_timeframe = exchange.get_option('funding_fee_timeframe')
|
||||
|
||||
logger.warning('Migrating funding fees to correct timeframe.')
|
||||
|
||||
dhc = get_datahandler(config['datadir'], config['dataformat_ohlcv'])
|
||||
dhc.fix_funding_fee_timeframe(ff_timeframe)
|
Loading…
Reference in New Issue
Block a user