freqtrade_origin/tests/utils/test_binance_mig.py

67 lines
2.1 KiB
Python
Raw Normal View History

2023-01-14 19:34:04 +00:00
import shutil
2023-01-14 19:54:42 +00:00
import pytest
from freqtrade.persistence import Trade
2024-01-04 16:08:57 +00:00
from freqtrade.util.migrations import (migrate_binance_futures_data, migrate_binance_futures_names,
migrate_data)
2023-01-14 19:54:42 +00:00
from tests.conftest import create_mock_trades_usdt, log_has
2023-01-14 19:34:04 +00:00
2023-11-05 15:15:36 +00:00
def test_binance_mig_data_conversion(default_conf_usdt, tmp_path, testdatadir):
2023-01-14 19:34:04 +00:00
# call doing nothing (spot mode)
migrate_binance_futures_data(default_conf_usdt)
default_conf_usdt['trading_mode'] = 'futures'
pair_old = 'XRP_USDT'
pair_unified = 'XRP_USDT_USDT'
futures_src = testdatadir / 'futures'
2023-11-05 15:15:36 +00:00
futures_dst = tmp_path / 'futures'
2023-01-14 19:34:04 +00:00
futures_dst.mkdir()
files = [
2023-07-09 14:19:22 +00:00
'-1h-mark.feather',
'-1h-futures.feather',
'-8h-funding_rate.feather',
'-8h-mark.feather',
2023-01-14 19:34:04 +00:00
]
# Copy files to tmpdir and rename to old naming
for file in files:
fn_after = futures_dst / f'{pair_old}{file}'
shutil.copy(futures_src / f'{pair_unified}{file}', fn_after)
2023-11-05 15:15:36 +00:00
default_conf_usdt['datadir'] = tmp_path
2023-01-14 19:34:04 +00:00
# Migrate files to unified namings
migrate_binance_futures_data(default_conf_usdt)
for file in files:
fn_after = futures_dst / f'{pair_unified}{file}'
assert fn_after.exists()
2023-01-14 19:54:42 +00:00
@pytest.mark.usefixtures("init_persistence")
def test_binance_mig_db_conversion(default_conf_usdt, fee, caplog):
# Does nothing in spot mode
migrate_binance_futures_names(default_conf_usdt)
create_mock_trades_usdt(fee, None)
for t in Trade.get_trades():
t.trading_mode = 'FUTURES'
t.exchange = 'binance'
Trade.commit()
default_conf_usdt['trading_mode'] = 'futures'
migrate_binance_futures_names(default_conf_usdt)
assert log_has('Migrating binance futures pairs in database.', caplog)
2024-01-04 16:08:57 +00:00
def test_migration_wrapper(default_conf_usdt, mocker):
default_conf_usdt['trading_mode'] = 'futures'
binmock = mocker.patch('freqtrade.util.migrations.migrate_binance_futures_data')
funding_mock = mocker.patch('freqtrade.util.migrations.migrate_funding_fee_timeframe')
migrate_data(default_conf_usdt)
assert binmock.call_count == 1
assert funding_mock.call_count == 1