Remove clean-dry-run code

This commit is contained in:
Matthias 2022-05-19 06:45:20 +02:00
parent 0a95ef6ab2
commit a3d9384bc0
9 changed files with 19 additions and 21 deletions

View File

@ -19,9 +19,9 @@ def start_convert_db(args: Dict[str, Any]) -> None:
config = setup_utils_configuration(args, RunMode.UTIL_NO_EXCHANGE) config = setup_utils_configuration(args, RunMode.UTIL_NO_EXCHANGE)
init_db(config['db_url'], False) init_db(config['db_url'])
session_target = Trade._session session_target = Trade._session
init_db(config['db_url_from'], False) init_db(config['db_url_from'])
logger.info("Starting db migration.") logger.info("Starting db migration.")
trade_count = 0 trade_count = 0

View File

@ -212,7 +212,7 @@ def start_show_trades(args: Dict[str, Any]) -> None:
raise OperationalException("--db-url is required for this command.") raise OperationalException("--db-url is required for this command.")
logger.info(f'Using DB: "{parse_db_uri_for_logging(config["db_url"])}"') logger.info(f'Using DB: "{parse_db_uri_for_logging(config["db_url"])}"')
init_db(config['db_url'], clean_open_orders=False) init_db(config['db_url'])
tfilter = [] tfilter = []
if config.get('trade_ids'): if config.get('trade_ids'):

View File

@ -353,7 +353,7 @@ def load_trades_from_db(db_url: str, strategy: Optional[str] = None) -> pd.DataF
Can also serve as protection to load the correct result. Can also serve as protection to load the correct result.
:return: Dataframe containing Trades :return: Dataframe containing Trades
""" """
init_db(db_url, clean_open_orders=False) init_db(db_url)
filters = [] filters = []
if strategy: if strategy:

View File

@ -67,7 +67,7 @@ class FreqtradeBot(LoggingMixin):
self.exchange = ExchangeResolver.load_exchange(self.config['exchange']['name'], self.config) self.exchange = ExchangeResolver.load_exchange(self.config['exchange']['name'], self.config)
init_db(self.config.get('db_url', None), clean_open_orders=self.config['dry_run']) init_db(self.config.get('db_url', None))
self.wallets = Wallets(self.config, self.exchange) self.wallets = Wallets(self.config, self.exchange)

View File

@ -1,5 +1,5 @@
# flake8: noqa: F401 # flake8: noqa: F401
from freqtrade.persistence.models import clean_dry_run_db, cleanup_db, init_db from freqtrade.persistence.models import cleanup_db, init_db
from freqtrade.persistence.pairlock_middleware import PairLocks from freqtrade.persistence.pairlock_middleware import PairLocks
from freqtrade.persistence.trade_model import LocalTrade, Order, Trade from freqtrade.persistence.trade_model import LocalTrade, Order, Trade

View File

@ -21,14 +21,12 @@ logger = logging.getLogger(__name__)
_SQL_DOCS_URL = 'http://docs.sqlalchemy.org/en/latest/core/engines.html#database-urls' _SQL_DOCS_URL = 'http://docs.sqlalchemy.org/en/latest/core/engines.html#database-urls'
def init_db(db_url: str, clean_open_orders: bool = False) -> None: def init_db(db_url: str) -> None:
""" """
Initializes this module with the given config, Initializes this module with the given config,
registers all known command handlers registers all known command handlers
and starts polling for message updates and starts polling for message updates
:param db_url: Database to use :param db_url: Database to use
:param clean_open_orders: Remove open orders from the database.
Useful for dry-run or if all orders have been reset on the exchange.
:return: None :return: None
""" """
kwargs = {} kwargs = {}

View File

@ -1495,7 +1495,7 @@ def test_start_convert_db(mocker, fee, tmpdir, caplog):
] ]
assert not db_src_file.is_file() assert not db_src_file.is_file()
init_db(db_from, False) init_db(db_from)
create_mock_trades(fee) create_mock_trades(fee)

View File

@ -384,7 +384,7 @@ def patch_coingekko(mocker) -> None:
@pytest.fixture(scope='function') @pytest.fixture(scope='function')
def init_persistence(default_conf): def init_persistence(default_conf):
init_db(default_conf['db_url'], default_conf['dry_run']) init_db(default_conf['db_url'])
@pytest.fixture(scope="function") @pytest.fixture(scope="function")

View File

@ -13,7 +13,7 @@ from sqlalchemy import create_engine, text
from freqtrade import constants from freqtrade import constants
from freqtrade.enums import TradingMode from freqtrade.enums import TradingMode
from freqtrade.exceptions import DependencyException, OperationalException from freqtrade.exceptions import DependencyException, OperationalException
from freqtrade.persistence import LocalTrade, Order, Trade, clean_dry_run_db, init_db from freqtrade.persistence import LocalTrade, Order, Trade, init_db
from freqtrade.persistence.migrations import get_last_sequence_ids, set_sequence_ids from freqtrade.persistence.migrations import get_last_sequence_ids, set_sequence_ids
from freqtrade.persistence.models import PairLock from freqtrade.persistence.models import PairLock
from tests.conftest import create_mock_trades, create_mock_trades_with_leverage, log_has, log_has_re from tests.conftest import create_mock_trades, create_mock_trades_with_leverage, log_has, log_has_re
@ -24,7 +24,7 @@ spot, margin, futures = TradingMode.SPOT, TradingMode.MARGIN, TradingMode.FUTURE
def test_init_create_session(default_conf): def test_init_create_session(default_conf):
# Check if init create a session # Check if init create a session
init_db(default_conf['db_url'], default_conf['dry_run']) init_db(default_conf['db_url'])
assert hasattr(Trade, '_session') assert hasattr(Trade, '_session')
assert 'scoped_session' in type(Trade._session).__name__ assert 'scoped_session' in type(Trade._session).__name__
@ -36,7 +36,7 @@ def test_init_custom_db_url(default_conf, tmpdir):
default_conf.update({'db_url': f'sqlite:///{filename}'}) default_conf.update({'db_url': f'sqlite:///{filename}'})
init_db(default_conf['db_url'], default_conf['dry_run']) init_db(default_conf['db_url'])
assert Path(filename).is_file() assert Path(filename).is_file()
r = Trade._session.execute(text("PRAGMA journal_mode")) r = Trade._session.execute(text("PRAGMA journal_mode"))
assert r.first() == ('wal',) assert r.first() == ('wal',)
@ -45,10 +45,10 @@ def test_init_custom_db_url(default_conf, tmpdir):
def test_init_invalid_db_url(): def test_init_invalid_db_url():
# Update path to a value other than default, but still in-memory # Update path to a value other than default, but still in-memory
with pytest.raises(OperationalException, match=r'.*no valid database URL*'): with pytest.raises(OperationalException, match=r'.*no valid database URL*'):
init_db('unknown:///some.url', True) init_db('unknown:///some.url')
with pytest.raises(OperationalException, match=r'Bad db-url.*For in-memory database, pl.*'): with pytest.raises(OperationalException, match=r'Bad db-url.*For in-memory database, pl.*'):
init_db('sqlite:///', True) init_db('sqlite:///')
def test_init_prod_db(default_conf, mocker): def test_init_prod_db(default_conf, mocker):
@ -57,7 +57,7 @@ def test_init_prod_db(default_conf, mocker):
create_engine_mock = mocker.patch('freqtrade.persistence.models.create_engine', MagicMock()) create_engine_mock = mocker.patch('freqtrade.persistence.models.create_engine', MagicMock())
init_db(default_conf['db_url'], default_conf['dry_run']) init_db(default_conf['db_url'])
assert create_engine_mock.call_count == 1 assert create_engine_mock.call_count == 1
assert create_engine_mock.mock_calls[0][1][0] == 'sqlite:///tradesv3.sqlite' assert create_engine_mock.mock_calls[0][1][0] == 'sqlite:///tradesv3.sqlite'
@ -70,7 +70,7 @@ def test_init_dryrun_db(default_conf, tmpdir):
'db_url': f'sqlite:///{filename}' 'db_url': f'sqlite:///{filename}'
}) })
init_db(default_conf['db_url'], default_conf['dry_run']) init_db(default_conf['db_url'])
assert Path(filename).is_file() assert Path(filename).is_file()
@ -1260,7 +1260,7 @@ def test_migrate_new(mocker, default_conf, fee, caplog):
connection.execute(text("create table trades_bak1 as select * from trades")) connection.execute(text("create table trades_bak1 as select * from trades"))
# Run init to test migration # Run init to test migration
init_db(default_conf['db_url'], default_conf['dry_run']) init_db(default_conf['db_url'])
assert len(Trade.query.filter(Trade.id == 1).all()) == 1 assert len(Trade.query.filter(Trade.id == 1).all()) == 1
trade = Trade.query.filter(Trade.id == 1).first() trade = Trade.query.filter(Trade.id == 1).first()
@ -1343,7 +1343,7 @@ def test_migrate_too_old(mocker, default_conf, fee, caplog):
# Run init to test migration # Run init to test migration
with pytest.raises(OperationalException, match=r'Your database seems to be very old'): with pytest.raises(OperationalException, match=r'Your database seems to be very old'):
init_db(default_conf['db_url'], default_conf['dry_run']) init_db(default_conf['db_url'])
def test_migrate_get_last_sequence_ids(): def test_migrate_get_last_sequence_ids():
@ -1417,7 +1417,7 @@ def test_migrate_pairlocks(mocker, default_conf, fee, caplog):
connection.execute(text(create_index2)) connection.execute(text(create_index2))
connection.execute(text(create_index3)) connection.execute(text(create_index3))
init_db(default_conf['db_url'], default_conf['dry_run']) init_db(default_conf['db_url'])
assert len(PairLock.query.all()) == 2 assert len(PairLock.query.all()) == 2
assert len(PairLock.query.filter(PairLock.pair == '*').all()) == 1 assert len(PairLock.query.filter(PairLock.pair == '*').all()) == 1