diff --git a/freqtrade/freqtradebot.py b/freqtrade/freqtradebot.py index 657e0bd82..390c8e8f6 100644 --- a/freqtrade/freqtradebot.py +++ b/freqtrade/freqtradebot.py @@ -26,7 +26,7 @@ from freqtrade.exchange import timeframe_to_minutes, timeframe_to_seconds from freqtrade.exchange.exchange import timeframe_to_next_date from freqtrade.misc import safe_value_fallback, safe_value_fallback2 from freqtrade.mixins import LoggingMixin -from freqtrade.persistence import Order, PairLocks, Trade, cleanup_db, init_db +from freqtrade.persistence import Order, PairLocks, Trade, init_db from freqtrade.plugins.pairlistmanager import PairListManager from freqtrade.plugins.protectionmanager import ProtectionManager from freqtrade.resolvers import ExchangeResolver, StrategyResolver @@ -150,7 +150,7 @@ class FreqtradeBot(LoggingMixin): self.check_for_open_trades() self.rpc.cleanup() - cleanup_db() + Trade.commit() self.exchange.close() def startup(self) -> None: @@ -1701,7 +1701,6 @@ class FreqtradeBot(LoggingMixin): self.handle_order_fee(trade, order_obj, order) trade.update_trade(order_obj) - Trade.commit() if order.get('status') in constants.NON_OPEN_EXCHANGE_STATES: # If a entry order was closed, force update on stoploss on exchange @@ -1725,6 +1724,7 @@ class FreqtradeBot(LoggingMixin): # Updating wallets when order is closed self.wallets.update() + Trade.commit() self.order_close_notify(trade, order_obj, stoploss_order, send_msg) diff --git a/freqtrade/persistence/__init__.py b/freqtrade/persistence/__init__.py index f4e7470a7..9e1a7e922 100644 --- a/freqtrade/persistence/__init__.py +++ b/freqtrade/persistence/__init__.py @@ -1,5 +1,5 @@ # flake8: noqa: F401 -from freqtrade.persistence.models import cleanup_db, init_db +from freqtrade.persistence.models import init_db from freqtrade.persistence.pairlock_middleware import PairLocks from freqtrade.persistence.trade_model import LocalTrade, Order, Trade diff --git a/freqtrade/persistence/models.py b/freqtrade/persistence/models.py index 86d2f9f9c..f0fa05343 100644 --- a/freqtrade/persistence/models.py +++ b/freqtrade/persistence/models.py @@ -61,11 +61,3 @@ def init_db(db_url: str) -> None: previous_tables = inspect(engine).get_table_names() _DECL_BASE.metadata.create_all(engine) check_migrate(engine, decl_base=_DECL_BASE, previous_tables=previous_tables) - - -def cleanup_db() -> None: - """ - Flushes all pending operations to disk. - :return: None - """ - Trade.commit() diff --git a/tests/test_freqtradebot.py b/tests/test_freqtradebot.py index 0b073a062..f274e2119 100644 --- a/tests/test_freqtradebot.py +++ b/tests/test_freqtradebot.py @@ -75,7 +75,7 @@ def test_process_calls_sendmsg(mocker, default_conf_usdt) -> None: def test_bot_cleanup(mocker, default_conf_usdt, caplog) -> None: - mock_cleanup = mocker.patch('freqtrade.freqtradebot.cleanup_db') + mock_cleanup = mocker.patch('freqtrade.freqtradebot.Trade.commit') coo_mock = mocker.patch('freqtrade.freqtradebot.FreqtradeBot.cancel_all_open_orders') freqtrade = get_patched_freqtradebot(mocker, default_conf_usdt) freqtrade.cleanup()