Add data migration method

This commit is contained in:
Matthias 2023-01-12 20:59:43 +01:00
parent b1bfd76741
commit ee7b505dcb
2 changed files with 36 additions and 2 deletions

View File

@ -374,6 +374,21 @@ class IDataHandler(ABC):
logger.warning(f"{pair}, {candle_type}, {timeframe}, " logger.warning(f"{pair}, {candle_type}, {timeframe}, "
f"data ends at {pairdata.iloc[-1]['date']:%Y-%m-%d %H:%M:%S}") f"data ends at {pairdata.iloc[-1]['date']:%Y-%m-%d %H:%M:%S}")
def rename_futures_data(
self, pair: str, new_pair: str, timeframe: str, candle_type: CandleType):
"""
Temporary method to migrate data from old naming to new naming (BTC/USDT -> BTC/USDT:USDT)
Only used for binance to support the binance futures naming unification.
"""
file_old = self._pair_data_filename(self._datadir, pair, timeframe, candle_type)
file_new = self._pair_data_filename(self._datadir, new_pair, timeframe, candle_type)
# print(file_old, file_new)
if file_new.exists():
logger.warning(f"{file_new} exists already, can't migrate {pair}.")
return
file_old.rename(file_new)
def get_datahandlerclass(datatype: str) -> Type[IDataHandler]: def get_datahandlerclass(datatype: str) -> Type[IDataHandler]:
""" """

View File

@ -18,10 +18,11 @@ def migrate_binance_futures_names(config: Config):
# only act on new futures # only act on new futures
return return
_migrate_binance_futures_db(config) _migrate_binance_futures_db(config)
_migrate_binance_futures_data(config)
def _migrate_binance_futures_db(config: Config): def _migrate_binance_futures_db(config: Config):
logger.warning('Migrating binance futures pairs') logger.warning('Migrating binance futures pairs in database.')
trades = Trade.get_trades([Trade.exchange == 'binance', Trade.trading_mode == 'FUTURES']).all() trades = Trade.get_trades([Trade.exchange == 'binance', Trade.trading_mode == 'FUTURES']).all()
for trade in trades: for trade in trades:
if ':' in trade.pair: if ':' in trade.pair:
@ -41,4 +42,22 @@ def _migrate_binance_futures_db(config: Config):
# print(pls) # print(pls)
# pls.update({'pair': concat(PairLock.pair,':USDT')}) # pls.update({'pair': concat(PairLock.pair,':USDT')})
Trade.commit() Trade.commit()
logger.warning('Done migrating binance futures pairs') logger.warning('Done migrating binance futures pairs in database.')
def _migrate_binance_futures_data(config: Config):
from freqtrade.data.history.idatahandler import get_datahandler
dhc = get_datahandler(config['datadir'], config['dataformat_ohlcv'])
paircombs = dhc.ohlcv_get_available_data(
config['datadir'],
config.get('trading_mode', TradingMode.SPOT)
)
for pair, timeframe, candle_type in paircombs:
if ':' in pair:
# already migrated
continue
new_pair = f"{pair}:{config['stake_currency']}"
dhc.rename_futures_data(pair, new_pair, timeframe, candle_type)