2023-01-12 19:36:06 +00:00
|
|
|
import logging
|
|
|
|
|
2023-01-16 05:54:29 +00:00
|
|
|
from packaging import version
|
2023-03-15 20:19:36 +00:00
|
|
|
from sqlalchemy import select
|
2023-01-16 05:54:29 +00:00
|
|
|
|
2023-06-17 07:10:54 +00:00
|
|
|
from freqtrade.constants import DOCS_LINK, Config
|
2023-09-10 16:10:38 +00:00
|
|
|
from freqtrade.enums import TradingMode
|
2023-01-15 14:53:41 +00:00
|
|
|
from freqtrade.exceptions import OperationalException
|
2023-01-12 19:36:06 +00:00
|
|
|
from freqtrade.persistence.pairlock import PairLock
|
|
|
|
from freqtrade.persistence.trade_model import Trade
|
|
|
|
|
|
|
|
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
|
|
|
def migrate_binance_futures_names(config: Config):
|
|
|
|
|
|
|
|
if (
|
2023-01-12 22:38:53 +00:00
|
|
|
not (config.get('trading_mode', TradingMode.SPOT) == TradingMode.FUTURES
|
2023-01-12 19:36:06 +00:00
|
|
|
and config['exchange']['name'] == 'binance')
|
|
|
|
):
|
|
|
|
# only act on new futures
|
|
|
|
return
|
2023-01-15 14:53:41 +00:00
|
|
|
import ccxt
|
2023-01-17 05:46:49 +00:00
|
|
|
if version.parse("2.6.26") > version.parse(ccxt.__version__):
|
2023-01-15 14:53:41 +00:00
|
|
|
raise OperationalException(
|
|
|
|
"Please follow the update instructions in the docs "
|
2023-06-17 07:10:54 +00:00
|
|
|
f"({DOCS_LINK}/updating/) to install a compatible ccxt version.")
|
2023-01-12 19:36:06 +00:00
|
|
|
_migrate_binance_futures_db(config)
|
2023-01-13 06:27:18 +00:00
|
|
|
migrate_binance_futures_data(config)
|
2023-01-12 19:36:06 +00:00
|
|
|
|
|
|
|
|
|
|
|
def _migrate_binance_futures_db(config: Config):
|
2023-01-12 19:59:43 +00:00
|
|
|
logger.warning('Migrating binance futures pairs in database.')
|
2023-01-12 19:36:06 +00:00
|
|
|
trades = Trade.get_trades([Trade.exchange == 'binance', Trade.trading_mode == 'FUTURES']).all()
|
|
|
|
for trade in trades:
|
|
|
|
if ':' in trade.pair:
|
|
|
|
# already migrated
|
|
|
|
continue
|
|
|
|
new_pair = f"{trade.pair}:{trade.stake_currency}"
|
|
|
|
trade.pair = new_pair
|
|
|
|
|
|
|
|
for order in trade.orders:
|
|
|
|
order.ft_pair = new_pair
|
|
|
|
# Should symbol be migrated too?
|
|
|
|
# order.symbol = new_pair
|
|
|
|
Trade.commit()
|
2023-03-15 20:19:36 +00:00
|
|
|
pls = PairLock.session.scalars(select(PairLock).filter(PairLock.pair.notlike('%:%'))).all()
|
2023-01-12 19:36:06 +00:00
|
|
|
for pl in pls:
|
|
|
|
pl.pair = f"{pl.pair}:{config['stake_currency']}"
|
|
|
|
# print(pls)
|
|
|
|
# pls.update({'pair': concat(PairLock.pair,':USDT')})
|
|
|
|
Trade.commit()
|
2023-01-12 19:59:43 +00:00
|
|
|
logger.warning('Done migrating binance futures pairs in database.')
|
|
|
|
|
|
|
|
|
2023-01-13 06:27:18 +00:00
|
|
|
def migrate_binance_futures_data(config: Config):
|
|
|
|
|
|
|
|
if (
|
|
|
|
not (config.get('trading_mode', TradingMode.SPOT) == TradingMode.FUTURES
|
|
|
|
and config['exchange']['name'] == 'binance')
|
|
|
|
):
|
|
|
|
# only act on new futures
|
|
|
|
return
|
2023-01-12 19:59:43 +00:00
|
|
|
|
|
|
|
from freqtrade.data.history.idatahandler import get_datahandler
|
2023-07-12 16:27:46 +00:00
|
|
|
dhc = get_datahandler(config['datadir'], config['dataformat_ohlcv'])
|
2023-01-12 19:59:43 +00:00
|
|
|
|
|
|
|
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)
|